From ffcb9e2c1a51ec868c3b0362fec9d25b9d78d4ec Mon Sep 17 00:00:00 2001 From: Aaron Scherer Date: Tue, 15 Dec 2015 13:17:40 -0500 Subject: [PATCH] Applied fixes from StyleCI --- src/Cache/LoggingCachePool.php | 5 ++-- src/CacheBundle.php | 8 ++--- src/Command/CacheFlushCommand.php | 6 ++-- src/DataCollector/CacheDataCollector.php | 29 +++++++++---------- src/DependencyInjection/CacheExtension.php | 6 ++-- .../Compiler/BaseCompilerPass.php | 6 ++-- .../Compiler/DataCollectorCompilerPass.php | 6 ++-- .../Compiler/DoctrineSupportCompilerPass.php | 16 +++++----- .../Compiler/SessionSupportCompilerPass.php | 6 ++-- src/DependencyInjection/Configuration.php | 22 +++++++------- src/Routing/RouterListener.php | 23 ++++++++++----- src/Session/SessionHandler.php | 10 +++---- tests/ContainerTest.php | 2 +- .../CacheExtensionTest.php | 5 +--- tests/TestCase.php | 25 ++++++++-------- 15 files changed, 86 insertions(+), 89 deletions(-) diff --git a/src/Cache/LoggingCachePool.php b/src/Cache/LoggingCachePool.php index 430aa25..e3a7bdf 100755 --- a/src/Cache/LoggingCachePool.php +++ b/src/Cache/LoggingCachePool.php @@ -13,7 +13,6 @@ use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; -use Psr\Cache\InvalidArgumentException; /** * @author Aaron Scherer @@ -21,7 +20,7 @@ class LoggingCachePool implements CacheItemPoolInterface { /** - * @var array $calls + * @type array */ private $calls = []; @@ -91,7 +90,7 @@ private function timeCall($name, array $arguments = null) $result = call_user_func_array([$this->cachePool, $name], $arguments); $time = microtime(true) - $start; - $object = (object)compact('name', 'arguments', 'start', 'time', 'result'); + $object = (object) compact('name', 'arguments', 'start', 'time', 'result'); return $object; } diff --git a/src/CacheBundle.php b/src/CacheBundle.php index 2302167..50abc54 100755 --- a/src/CacheBundle.php +++ b/src/CacheBundle.php @@ -11,19 +11,19 @@ namespace Cache\CacheBundle; -use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Cache\CacheBundle\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * Class AequasiCacheBundle + * Class AequasiCacheBundle. * * @author Aaron Scherer */ class CacheBundle extends Bundle { /** - * {@inheritDoc} + * {@inheritdoc} */ public function build(ContainerBuilder $container) { diff --git a/src/Command/CacheFlushCommand.php b/src/Command/CacheFlushCommand.php index 2484d83..0a39aff 100755 --- a/src/Command/CacheFlushCommand.php +++ b/src/Command/CacheFlushCommand.php @@ -14,9 +14,9 @@ use Cache\Taggable\TaggablePoolInterface; use Psr\Cache\CacheItemPoolInterface; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; /** * Class CacheFlushCommand. @@ -41,7 +41,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $validTypes = ['session', 'routing', 'doctrine']; - $type = $input->getArgument('type'); + $type = $input->getArgument('type'); if ($type === 'all') { foreach ($validTypes as $type) { $this->clearCacheForType($type); @@ -69,7 +69,7 @@ private function clearCacheForType($type) { $serviceId = $this->getContainer()->getParameter(sprintf('cache.%s%.service_id', $type)); - /** @var CacheItemPoolInterface $service */ + /** @type CacheItemPoolInterface $service */ $service = $this->getContainer()->get($serviceId); if ($service instanceof TaggablePoolInterface) { $service->clear([$type]); diff --git a/src/DataCollector/CacheDataCollector.php b/src/DataCollector/CacheDataCollector.php index 0e9e16e..a551b74 100755 --- a/src/DataCollector/CacheDataCollector.php +++ b/src/DataCollector/CacheDataCollector.php @@ -12,33 +12,32 @@ namespace Cache\CacheBundle\DataCollector; use Cache\CacheBundle\Cache\LoggingCachePool; -use Cache\CacheBundle\Service\CacheService; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector; /** - * Class CacheDataCollector + * Class CacheDataCollector. * * @author Aaron Scherer */ class CacheDataCollector extends DataCollector { /** - * Template name + * Template name. * * @type string */ const TEMPLATE = 'CacheBundle:Collector:cache.html.twig'; /** - * @var LoggingCachePool[] + * @type LoggingCachePool[] */ private $instances = []; /** - * @param $name - * @param LoggingCachePool $instance + * @param $name + * @param LoggingCachePool $instance */ public function addInstance($name, LoggingCachePool $instance) { @@ -59,7 +58,7 @@ public function collect(Request $request, Response $response, \Exception $except $empty = ['calls' => [], 'config' => [], 'options' => [], 'statistics' => []]; $this->data = ['instances' => $empty, 'total' => $empty]; foreach ($this->instances as $name => $instance) { - $calls = $instance->getCalls(); + $calls = $instance->getCalls(); $this->data['instances']['calls'][$name] = $calls; } $this->data['instances']['statistics'] = $this->calculateStatistics(); @@ -79,7 +78,7 @@ public function getName() } /** - * Method returns amount of logged Cache reads: "get" calls + * Method returns amount of logged Cache reads: "get" calls. * * @return array */ @@ -89,7 +88,7 @@ public function getStatistics() } /** - * Method returns the statistic totals + * Method returns the statistic totals. * * @return array */ @@ -99,7 +98,7 @@ public function getTotals() } /** - * Method returns all logged Cache call objects + * Method returns all logged Cache call objects. * * @return mixed */ @@ -122,24 +121,24 @@ private function calculateStatistics() 'hits' => 0, 'misses' => 0, 'writes' => 0, - 'deletes' => 0 + 'deletes' => 0, ]; foreach ($calls as $call) { $statistics[$name]['calls'] += 1; $statistics[$name]['time'] += $call->time; - if ($call->name == 'fetch') { + if ($call->name === 'fetch') { $statistics[$name]['reads'] += 1; if ($call->result !== false) { $statistics[$name]['hits'] += 1; } else { $statistics[$name]['misses'] += 1; } - } elseif ($call->name == 'contains' && $call->result === false) { + } elseif ($call->name === 'contains' && $call->result === false) { $statistics[$name]['reads'] += 1; $statistics[$name]['misses'] += 1; - } elseif ($call->name == 'save') { + } elseif ($call->name === 'save') { $statistics[$name]['writes'] += 1; - } elseif ($call->name == 'delete') { + } elseif ($call->name === 'delete') { $statistics[$name]['deletes'] += 1; } } diff --git a/src/DependencyInjection/CacheExtension.php b/src/DependencyInjection/CacheExtension.php index 36e6bde..e8fc0fe 100755 --- a/src/DependencyInjection/CacheExtension.php +++ b/src/DependencyInjection/CacheExtension.php @@ -13,20 +13,18 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader; - /** - * * @author Aaron Scherer * @author Tobias Nyholm */ class CacheExtension extends Extension { /** - * Loads the configs for Cache and puts data into the container + * Loads the configs for Cache and puts data into the container. * * @param array $configs Array of configs * @param ContainerBuilder $container Container Object diff --git a/src/DependencyInjection/Compiler/BaseCompilerPass.php b/src/DependencyInjection/Compiler/BaseCompilerPass.php index 91b94e0..d6f8aed 100755 --- a/src/DependencyInjection/Compiler/BaseCompilerPass.php +++ b/src/DependencyInjection/Compiler/BaseCompilerPass.php @@ -15,19 +15,19 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * Class BaseCompilerPass + * Class BaseCompilerPass. * * @author Aaron Scherer */ abstract class BaseCompilerPass implements CompilerPassInterface { /** - * @var ContainerBuilder + * @type ContainerBuilder */ protected $container; /** - * {@inheritDoc} + * {@inheritdoc} */ public function process(ContainerBuilder $container) { diff --git a/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php b/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php index 3343833..c7eb729 100755 --- a/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php +++ b/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Class DataCollectorCompilerPass + * Class DataCollectorCompilerPass. * * @author Aaron Scherer * @author Tobias Nyholm @@ -23,12 +23,12 @@ class DataCollectorCompilerPass extends BaseCompilerPass { /** - * {@inheritDoc} + * {@inheritdoc} */ protected function prepare() { $collectorDefinition = $this->container->getDefinition('data_collector.cache'); - $serviceIds = $this->container->findTaggedServiceIds('cache.provider'); + $serviceIds = $this->container->findTaggedServiceIds('cache.provider'); foreach (array_keys($serviceIds) as $id) { diff --git a/src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php b/src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php index 205c541..c98922d 100755 --- a/src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php +++ b/src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php @@ -13,11 +13,10 @@ use Cache\Bridge\DoctrineCacheBridge; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; -use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; /** - * Class DoctrineSupportCompilerPass + * Class DoctrineSupportCompilerPass. * * @author Aaron Scherer * @author Tobias Nyholm @@ -25,8 +24,9 @@ class DoctrineSupportCompilerPass extends BaseCompilerPass { /** - * @return void * @throws \Exception + * + * @return void */ protected function prepare() { @@ -37,7 +37,7 @@ protected function prepare() if (!$this->hasDoctrine()) { throw new \Exception( - "Not able to find any doctrine caches to implement. Ensure you have Doctrine ORM or ODM" + 'Not able to find any doctrine caches to implement. Ensure you have Doctrine ORM or ODM' ); } @@ -68,15 +68,15 @@ protected function enableDoctrineSupport(array $config) // Doctrine can't talk to a PSR-6 cache, so we need a bridge $bridgeServiceId = sprintf('cache.provider.doctrine.%s.bridge', $cacheType); - $bridgeDef = $this->container->register($bridgeServiceId, DoctrineCacheBridge::class); + $bridgeDef = $this->container->register($bridgeServiceId, DoctrineCacheBridge::class); $bridgeDef->addArgument(0, new Reference($cacheData['service_id'])) ->setPublic(false); foreach ($cacheData[$type] as $manager) { $doctrineDefinitionId = sprintf( - "doctrine.%s.%s_%s_cache", - ($type == 'entity_managers' ? 'orm' : 'odm'), + 'doctrine.%s.%s_%s_cache', + ($type === 'entity_managers' ? 'orm' : 'odm'), $manager, $cacheType ); @@ -89,7 +89,7 @@ protected function enableDoctrineSupport(array $config) } /** - * Checks to see if there are ORM's or ODM's + * Checks to see if there are ORM's or ODM's. * * @return bool */ diff --git a/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php b/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php index 7f00933..9c21d26 100755 --- a/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php +++ b/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Class SessionSupportCompilerPass + * Class SessionSupportCompilerPass. * * @author Aaron Scherer */ @@ -35,14 +35,14 @@ protected function prepare() // If there is no active session support, throw if (!$this->container->hasAlias('session.storage')) { - throw new \Exception("Session cache support cannot be enabled if there is no session.storage service"); + throw new \Exception('Session cache support cannot be enabled if there is no session.storage service'); } $this->enableSessionSupport($this->container->getParameter($this->getAlias().'.session')); } /** - * Enables session support for memcached + * Enables session support for memcached. * * @param array $config Configuration for bundle * diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 1be0c2f..a14ca95 100755 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -16,7 +16,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * Class Configuration + * Class Configuration. * * @author Aaron Scherer */ @@ -42,7 +42,7 @@ public function getConfigTreeBuilder() } /** - * Configure the "cache.session" section + * Configure the "cache.session" section. * * @return ArrayNodeDefinition */ @@ -59,17 +59,16 @@ private function addSessionSupportSection() ->end() ->scalarNode('service_id')->isRequired()->end() ->scalarNode('prefix') - ->defaultValue("session_") + ->defaultValue('session_') ->end() ->scalarNode('ttl')->end() - ->end() - ; + ->end(); return $node; } /** - * Configure the "cache.doctrine" section + * Configure the "cache.doctrine" section. * * @return ArrayNodeDefinition */ @@ -85,10 +84,9 @@ private function addDoctrineSection() ->defaultFalse() ->isRequired() ->end() - ->end() - ; + ->end(); - $types = array('metadata', 'result', 'query'); + $types = ['metadata', 'result', 'query']; foreach ($types as $type) { $node->children() ->arrayNode($type) @@ -96,7 +94,7 @@ private function addDoctrineSection() ->children() ->scalarNode('service_id')->isRequired()->end() ->arrayNode('entity_managers') - ->defaultValue(array()) + ->defaultValue([]) ->beforeNormalization() ->ifString() ->then( @@ -108,7 +106,7 @@ function ($v) { ->prototype('scalar')->end() ->end() ->arrayNode('document_managers') - ->defaultValue(array()) + ->defaultValue([]) ->beforeNormalization() ->ifString() ->then( @@ -127,7 +125,7 @@ function ($v) { } /** - * Configure the "cache.router" section + * Configure the "cache.router" section. * * @return ArrayNodeDefinition */ diff --git a/src/Routing/RouterListener.php b/src/Routing/RouterListener.php index 5c54ee2..675c97b 100644 --- a/src/Routing/RouterListener.php +++ b/src/Routing/RouterListener.php @@ -1,13 +1,20 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Cache\CacheBundle\Routing; use Cache\Taggable\TaggablePoolInterface; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\KernelEvents; /** * @author Tobias Nyholm @@ -15,12 +22,12 @@ class RouterListener { /** - * @var CacheItemPoolInterface + * @type CacheItemPoolInterface */ private $cache; /** - * @var int + * @type int */ private $ttl; @@ -92,7 +99,7 @@ public function onAfterRouting(GetResponseEvent $event) */ private function createCacheKey(Request $request) { - $key = sprintf('route:%s:%s:%s',$request->getMethod(),$request->getHost(),$request->getPathInfo()); + $key = sprintf('route:%s:%s:%s', $request->getMethod(), $request->getHost(), $request->getPathInfo()); // This might be optional //$key.=':'.$this->implodeRecursive('|', $request->query->all()); @@ -109,11 +116,11 @@ private function createCacheKey(Request $request) private function implodeRecursive($separator, array $array) { $output = ''; - foreach ($array as $key=>$value) { + foreach ($array as $key => $value) { if (is_array($value)) { - $output.=sprintf('%s%s[%s]', $separator, $key, $this->implodeRecursive($separator, $value)); + $output .= sprintf('%s%s[%s]', $separator, $key, $this->implodeRecursive($separator, $value)); } else { - $output.=$separator.$value; + $output .= $separator.$value; } } diff --git a/src/Session/SessionHandler.php b/src/Session/SessionHandler.php index 0c93476..2d66b7c 100755 --- a/src/Session/SessionHandler.php +++ b/src/Session/SessionHandler.php @@ -22,17 +22,17 @@ class SessionHandler implements \SessionHandlerInterface { /** - * @var CacheItemPoolInterface Cache driver. + * @type CacheItemPoolInterface Cache driver. */ private $cache; /** - * @var int Time to live in seconds + * @type int Time to live in seconds */ private $ttl; /** - * @var string Key prefix for shared environments. + * @type string Key prefix for shared environments. */ private $prefix; @@ -48,11 +48,11 @@ class SessionHandler implements \SessionHandlerInterface * * @throws \InvalidArgumentException When unsupported options are passed */ - public function __construct(CacheItemPoolInterface $cache, array $options = array()) + public function __construct(CacheItemPoolInterface $cache, array $options = []) { $this->cache = $cache; - $this->ttl = isset($options['ttl']) ? (int) $options['ttl'] : 86400; + $this->ttl = isset($options['ttl']) ? (int) $options['ttl'] : 86400; $this->prefix = isset($options['prefix']) ? $options['prefix'] : 'sf2ses_'; } diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index 363c2ea..9c8e561 100755 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -12,7 +12,7 @@ namespace Cache\CacheBundle\Tests; /** - * Class ContainerTest + * Class ContainerTest. * * @author Aaron Scherer */ diff --git a/tests/DependencyInjection/CacheExtensionTest.php b/tests/DependencyInjection/CacheExtensionTest.php index 747e611..2ca62e8 100755 --- a/tests/DependencyInjection/CacheExtensionTest.php +++ b/tests/DependencyInjection/CacheExtensionTest.php @@ -12,17 +12,14 @@ namespace Cache\CacheBundle\Tests\DependencyInjection; use Cache\CacheBundle\Tests\TestCase; -use Aequasi\Cache\DoctrineCacheBridge; -use Psr\Cache\CacheItemPoolInterface; /** - * Class CacheExtensionTest + * Class CacheExtensionTest. * * @author Aaron Scherer */ class CacheExtensionTest extends TestCase { - /** * */ diff --git a/tests/TestCase.php b/tests/TestCase.php index a00c297..56da9e2 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -12,27 +12,26 @@ namespace Cache\CacheBundle\Tests; use Cache\CacheBundle\DependencyInjection\CacheExtension; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; /** - * Class TestCase + * Class TestCase. * * @author Aaron Scherer */ class TestCase extends \PHPUnit_Framework_TestCase { - /** * @param ContainerBuilder $container * @param string $file */ protected function loadFromFile(ContainerBuilder $container, $file) { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures')); - $loader->load($file . '.yml'); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures')); + $loader->load($file.'.yml'); } /** @@ -40,17 +39,17 @@ protected function loadFromFile(ContainerBuilder $container, $file) * * @return ContainerBuilder */ - protected function createContainer(array $data = array()) + protected function createContainer(array $data = []) { return new ContainerBuilder(new ParameterBag(array_merge( - array( - 'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'), + [ + 'kernel.bundles' => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'], 'kernel.cache_dir' => __DIR__, 'kernel.debug' => false, 'kernel.environment' => 'test', 'kernel.name' => 'kernel', 'kernel.root_dir' => __DIR__, - ), + ], $data ))); } @@ -61,16 +60,16 @@ protected function createContainer(array $data = array()) * * @return ContainerBuilder */ - protected function createContainerFromFile($file, $data = array()) + protected function createContainerFromFile($file, $data = []) { $container = $this->createContainer($data); $container->registerExtension(new CacheExtension()); $this->loadFromFile($container, $file); $container->getCompilerPassConfig() - ->setOptimizationPasses(array()); + ->setOptimizationPasses([]); $container->getCompilerPassConfig() - ->setRemovingPasses(array()); + ->setRemovingPasses([]); $container->compile(); return $container;