Skip to content

Applied fixes from StyleCI #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Cache/LoggingCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;

/**
* @author Aaron Scherer <[email protected]>
*/
class LoggingCachePool implements CacheItemPoolInterface
{
/**
* @var array $calls
* @type array
*/
private $calls = [];

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/CacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
class CacheBundle extends Bundle
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Command/CacheFlushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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]);
Expand Down
29 changes: 14 additions & 15 deletions src/DataCollector/CacheDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
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)
{
Expand All @@ -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();
Expand All @@ -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
*/
Expand All @@ -89,7 +88,7 @@ public function getStatistics()
}

/**
* Method returns the statistic totals
* Method returns the statistic totals.
*
* @return array
*/
Expand All @@ -99,7 +98,7 @@ public function getTotals()
}

/**
* Method returns all logged Cache call objects
* Method returns all logged Cache call objects.
*
* @return mixed
*/
Expand All @@ -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;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/DependencyInjection/CacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Tobias Nyholm <[email protected]>
*/
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
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Compiler/BaseCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Class BaseCompilerPass
* Class BaseCompilerPass.
*
* @author Aaron Scherer <[email protected]>
*/
abstract class BaseCompilerPass implements CompilerPassInterface
{
/**
* @var ContainerBuilder
* @type ContainerBuilder
*/
protected $container;

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Class DataCollectorCompilerPass
* Class DataCollectorCompilerPass.
*
* @author Aaron Scherer <[email protected]>
* @author Tobias Nyholm <[email protected]>
*/
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) {

Expand Down
16 changes: 8 additions & 8 deletions src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@

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 <[email protected]>
* @author Tobias Nyholm <[email protected]>
*/
class DoctrineSupportCompilerPass extends BaseCompilerPass
{
/**
* @return void
* @throws \Exception
*
* @return void
*/
protected function prepare()
{
Expand All @@ -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'
);
}

Expand Down Expand Up @@ -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
);
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Class SessionSupportCompilerPass
* Class SessionSupportCompilerPass.
*
* @author Aaron Scherer <[email protected]>
*/
Expand All @@ -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
*
Expand Down
Loading