public function testGetCachedReturnsNullIfCacheIsNotExisting() { $filesystem = $this->prophesize('Symfony\\Component\\Filesystem\\Filesystem'); $filesystem->exists('.rules/id')->willReturn(false); $cache = new Cache($filesystem->reveal()); $this->assertNull($cache->getCachedRuleSet('id')); }
/** * {@inheritdoc} */ public function loadRuleSet($path) { $key = $this->generateDirectoryKey($path); if ($this->cache->has($key)) { return $this->cache->getCachedRuleSet($key); } $ruleSet = $this->traverser->traverse($path); $this->cache->cacheRuleSet($key, $ruleSet); return $ruleSet; }
/** * @param Package $package * * @return RuleSet */ private function loadPackageRuleSet(Package $package) { $ruleSet = new RuleSet(); $key = $package->generatePackageKey(); if ($this->cache->has($key)) { $ruleSet = $this->cache->getCachedRuleSet($key); } elseif (is_dir($path = $package->getPackagePath(self::PACKAGE_PATH))) { $ruleSet = $this->traverser->traverse($path); $this->cache->cacheRuleSet($key, $ruleSet); } else { // there is no vendor package in the given path } return $ruleSet; }
/** * @param $package * * @return RuleSet|null */ private function loadPackageRuleSet(\stdClass $package) { $ruleSet = null; $key = $this->generatePackageKey($package); if ($this->cache->has($key)) { $ruleSet = $this->cache->getCachedRuleSet($key); } elseif (is_dir($path = $this->getPackagePath($package))) { $ruleSet = $this->traverser->traverse($path, true); $this->cache->cacheRuleSet($key, $ruleSet); } return $ruleSet; }
/** * @param DirectoryTraverser $traverser * @param Configuration $configuration * * @return LoaderInterface */ private function getRuleSetLoader(DirectoryTraverser $traverser, Configuration $configuration) { $ruleSetCache = new Cache(new Filesystem()); if ($configuration->useCachedRuleSet()) { $ruleSetCache->disable(); } else { $ruleSetCache->setCacheDir($configuration->ruleSetCacheDir()); } if (is_dir($configuration->ruleSet())) { $loader = new DirectoryLoader($traverser, $ruleSetCache); } elseif ('composer.lock' === basename($configuration->ruleSet())) { $loader = new ComposerLoader($traverser, $ruleSetCache, new ComposerFactory()); } else { $loader = new FileLoader(); } return $loader; }