PhpCsFixer\Cache\FileHandler::read PHP Method

read() public method

public read ( )
    public function read()
    {
        if (!file_exists($this->file)) {
            return;
        }
        $content = file_get_contents($this->file);
        try {
            $cache = Cache::fromJson($content);
        } catch (\InvalidArgumentException $exception) {
            return;
        }
        return $cache;
    }

Usage Example

Example #1
0
 public function testReadReturnsCache()
 {
     $file = $this->getFile();
     $signature = new Signature(PHP_VERSION, '2.0', true, array('foo', 'bar'));
     $cache = new Cache($signature);
     file_put_contents($file, $cache->toJson());
     $handler = new FileHandler($file);
     $cached = $handler->read();
     $this->assertInstanceOf('PhpCsFixer\\Cache\\CacheInterface', $cached);
     $this->assertTrue($cached->getSignature()->equals($signature));
 }