Skip to content

Commit

Permalink
PHP CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klavig committed Jan 22, 2021
1 parent f5d8f28 commit 873c8fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
8 changes: 4 additions & 4 deletions Imagine/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class CacheManager
protected $defaultResolver;

/**
* @var bool
* @var CacheWarmer
*/
private $webpGenerate;
protected $cacheWarmer;

/**
* @var CacheWarmer
* @var bool
*/
protected $cacheWarmer;
private $webpGenerate;

/**
* Constructs the cache manager to handle Resolvers based on the provided FilterConfiguration.
Expand Down
40 changes: 23 additions & 17 deletions Imagine/Cache/CacheWarmer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Liip\ImagineBundle\Imagine\Cache;

use Liip\ImagineBundle\Imagine\Cache\Warmer\WarmerInterface;
Expand All @@ -13,11 +22,10 @@
*/
class CacheWarmer
{

/**
* @var WarmerInterface[]
*/
protected $warmers = array();
protected $warmers = [];

/**
* Chunk size to query warmer in one step
Expand Down Expand Up @@ -97,34 +105,34 @@ public function addWarmer($name, WarmerInterface $warmer)

/**
* @param bool $force If set to true, cache is warmed up for paths already stored in cached (regenerate thumbs)
* @param null|array $selectedWarmers An optional array of warmers to process, if null - all warmers will be processed
* @param array|null $selectedWarmers An optional array of warmers to process, if null - all warmers will be processed
*
* @return void
* @throws \InvalidArgumentException
*
* @return void
*/
public function warm($force = false, $selectedWarmers = null)
{
$filtersByWarmer = $this->getFiltersByWarmers();
if (!$filtersByWarmer) {
$this->log(sprintf('No warmes are configured - add some as `warmers` param in your filter sets'));
$this->log('No warmes are configured - add some as `warmers` param in your filter sets');

return;
}

foreach ($filtersByWarmer as $warmerName => $filters) {
if (isset($selectedWarmers) && !empty($selectedWarmers) && !in_array($warmerName, $selectedWarmers)) {
if (isset($selectedWarmers) && !empty($selectedWarmers) && !in_array($warmerName, $selectedWarmers, true)) {
$this->log(
sprintf(
'Skipping warmer %s as it\'s not listed in selected warmers: [%s]',
$warmerName,
join(', ', $selectedWarmers)
implode(', ', $selectedWarmers)
)
);
continue;
}
if (!isset($this->warmers[$warmerName])) {
throw new \InvalidArgumentException(sprintf(
'Could not find warmer "%s"', $warmerName
));
throw new \InvalidArgumentException(sprintf('Could not find warmer "%s"', $warmerName));
}

$this->log(sprintf('Processing warmer "%s"', $warmerName));
Expand Down Expand Up @@ -153,9 +161,7 @@ public function clearWarmed($paths, $filters)
foreach ($filtersByWarmer as $warmerName => $warmerFilters) {
if (array_intersect($filters, $warmerFilters)) {
if (!isset($this->warmers[$warmerName])) {
throw new \InvalidArgumentException(sprintf(
'Could not find warmer "%s"', $warmerName
));
throw new \InvalidArgumentException(sprintf('Could not find warmer "%s"', $warmerName));
}
$warmer = $this->warmers[$warmerName];
$warmer->clearWarmed($paths);
Expand All @@ -166,12 +172,12 @@ public function clearWarmed($paths, $filters)
protected function getFiltersByWarmers()
{
$all = $this->filterManager->getFilterConfiguration()->all();
$warmers = array();
$warmers = [];
foreach ($all as $filterSet => $config) {
if (isset($config['warmers']) && $config['warmers']) {
foreach ($config['warmers'] as $warmer) {
if (!isset($warmers[$warmer])) {
$warmers[$warmer] = array($filterSet);
$warmers[$warmer] = [$filterSet];
} else {
$warmers[$warmer][] = $filterSet;
}
Expand All @@ -194,14 +200,14 @@ protected function warmPaths($paths, $filters, $force)
$successfulWarmedPaths = [];
foreach ($paths as $pathData) {
$aPath = $pathData['path'];
$binaries = array();
$binaries = [];
foreach ($filters as $filter) {
$this->log(sprintf('Warming up path "%s" for filter "%s"', $aPath, $filter));

$isStored = $this->cacheManager->isStored($aPath, $filter);
if ($force || !$isStored) {
// this is to avoid loading binary with the same loader for multiple filters
$loader = $this->dataManager->getLoader($filter);
$loader = $this->dataManager->getLoader($filter);
$isStored = false;

try {
Expand Down
2 changes: 1 addition & 1 deletion LiipImagineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new PostProcessorsCompilerPass());
$container->addCompilerPass(new ResolversCompilerPass());
$container->addCompilerPass(new MetadataReaderCompilerPass());
$container->addCompilerPass(new CacheWarmersCompilerPass);
$container->addCompilerPass(new CacheWarmersCompilerPass());

if (class_exists(AddTopicMetaPass::class)) {
$container->addCompilerPass(AddTopicMetaPass::create()
Expand Down

0 comments on commit 873c8fb

Please sign in to comment.