Skip to content

Commit

Permalink
Merge pull request #1058 from robfrawley/feature-global-update-cs-usi…
Browse files Browse the repository at this point in the history
…ng-php-cs-fixer

[CS] Globally update code style using new php-cs-fixer rules
  • Loading branch information
robfrawley committed Mar 2, 2018
2 parents 04ee7a1 + 4c321e0 commit 248d9f1
Show file tree
Hide file tree
Showing 102 changed files with 1,864 additions and 1,866 deletions.
2 changes: 1 addition & 1 deletion Async/ResolveCache.php
Expand Up @@ -88,7 +88,7 @@ public static function jsonDeserialize(string $json): self
throw new LogicException('The message does not contain "path" but it is required.');
}

if (!(is_null($data['filters']) || is_array($data['filters']))) {
if (!(null === $data['filters'] || is_array($data['filters']))) {
throw new LogicException('The message filters could be either null or array.');
}

Expand Down
2 changes: 1 addition & 1 deletion Async/ResolveCacheProcessor.php
Expand Up @@ -15,10 +15,10 @@
use Enqueue\Client\ProducerInterface;
use Enqueue\Consumption\QueueSubscriberInterface;
use Enqueue\Consumption\Result;
use Enqueue\Util\JSON;
use Interop\Queue\PsrContext;
use Interop\Queue\PsrMessage;
use Interop\Queue\PsrProcessor;
use Enqueue\Util\JSON;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Liip\ImagineBundle\Service\FilterService;

Expand Down
36 changes: 18 additions & 18 deletions Binary/Loader/AbstractDoctrineLoader.php
Expand Up @@ -36,24 +36,6 @@ public function __construct(ObjectManager $manager, $class = null)
$this->class = $class;
}

/**
* Map the requested path (ie. subpath in the URL) to an id that can be used to lookup the image in the Doctrine store.
*
* @param string $path
*
* @return string
*/
abstract protected function mapPathToId($path);

/**
* Return a stream resource from the Doctrine entity/document with the image content.
*
* @param object $image
*
* @return resource
*/
abstract protected function getStreamFromImage($image);

/**
* {@inheritdoc}
*/
Expand All @@ -75,4 +57,22 @@ public function find($path)

return stream_get_contents($this->getStreamFromImage($image));
}

/**
* Map the requested path (ie. subpath in the URL) to an id that can be used to lookup the image in the Doctrine store.
*
* @param string $path
*
* @return string
*/
abstract protected function mapPathToId($path);

/**
* Return a stream resource from the Doctrine entity/document with the image content.
*
* @param object $image
*
* @return resource
*/
abstract protected function getStreamFromImage($image);
}
2 changes: 1 addition & 1 deletion Binary/Loader/FlysystemLoader.php
Expand Up @@ -41,7 +41,7 @@ public function __construct(
*/
public function find($path)
{
if ($this->filesystem->has($path) === false) {
if (false === $this->filesystem->has($path)) {
throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
}

Expand Down
4 changes: 2 additions & 2 deletions Binary/Locator/FileSystemInsecureLocator.php
Expand Up @@ -21,8 +21,8 @@ class FileSystemInsecureLocator extends FileSystemLocator
*/
protected function generateAbsolutePath($root, $path)
{
if (false !== strpos($path, '..'.DIRECTORY_SEPARATOR) ||
false !== strpos($path, DIRECTORY_SEPARATOR.'..') ||
if (false !== mb_strpos($path, '..'.DIRECTORY_SEPARATOR) ||
false !== mb_strpos($path, DIRECTORY_SEPARATOR.'..') ||
false === file_exists($absolute = $root.DIRECTORY_SEPARATOR.$path)) {
return false;
}
Expand Down
26 changes: 13 additions & 13 deletions Binary/Locator/FileSystemLocator.php
Expand Up @@ -61,6 +61,17 @@ public function locate($path)
$path, implode(':', $this->roots)));
}

/**
* @param string $root
* @param string $path
*
* @return string|false
*/
protected function generateAbsolutePath($root, $path)
{
return realpath($root.DIRECTORY_SEPARATOR.$path);
}

/**
* @param string $path
*
Expand All @@ -84,7 +95,7 @@ private function locateUsingRootPathsSearch($path)
*/
private function locateUsingRootPlaceholder($path)
{
if (0 !== strpos($path, '@') || 1 !== preg_match('{@(?<name>[^:]+):(?<path>.+)}', $path, $matches)) {
if (0 !== mb_strpos($path, '@') || 1 !== preg_match('{@(?<name>[^:]+):(?<path>.+)}', $path, $matches)) {
return false;
}

Expand All @@ -96,17 +107,6 @@ private function locateUsingRootPlaceholder($path)
$matches['name'], $matches['path']));
}

/**
* @param string $root
* @param string $path
*
* @return string|false
*/
protected function generateAbsolutePath($root, $path)
{
return realpath($root.DIRECTORY_SEPARATOR.$path);
}

/**
* @param string $root
*
Expand All @@ -133,7 +133,7 @@ private function sanitizeRootPath($root)
private function sanitizeAbsolutePath($path)
{
foreach ($this->roots as $root) {
if (0 === strpos($path, $root)) {
if (0 === mb_strpos($path, $root)) {
return $path;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Controller/ImagineController.php
Expand Up @@ -75,7 +75,7 @@ public function filterAction(Request $request, $path, $filter)
try {
return new RedirectResponse($this->filterService->getUrlOfFilteredImage($path, $filter, $resolver), 301);
} catch (NotLoadableException $e) {
if ($this->dataManager->getDefaultImageUrl($filter) !== null) {
if (null !== $this->dataManager->getDefaultImageUrl($filter)) {
return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter));
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public function filterRuntimeAction(Request $request, $hash, $path, $filter)
try {
return new RedirectResponse($this->filterService->getUrlOfFilteredImageWithRuntimeFilters($path, $filter, $runtimeConfig, $resolver), 301);
} catch (NotLoadableException $e) {
if ($this->dataManager->getDefaultImageUrl($filter) !== null) {
if (null !== $this->dataManager->getDefaultImageUrl($filter)) {
return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter));
}

Expand Down
12 changes: 6 additions & 6 deletions DependencyInjection/Compiler/MetadataReaderCompilerPass.php
Expand Up @@ -49,20 +49,20 @@ public function process(ContainerBuilder $container): void
}

/**
* @param ContainerBuilder $container
*
* @return bool
*/
private function isExifMetadataReaderSet(ContainerBuilder $container): bool
protected function isExifExtensionLoaded(): bool
{
return $container->getDefinition(self::$metadataReaderServiceId)->getClass() === self::$metadataReaderExifClass;
return extension_loaded('exif');
}

/**
* @param ContainerBuilder $container
*
* @return bool
*/
protected function isExifExtensionLoaded(): bool
private function isExifMetadataReaderSet(ContainerBuilder $container): bool
{
return extension_loaded('exif');
return $container->getDefinition(self::$metadataReaderServiceId)->getClass() === self::$metadataReaderExifClass;
}
}
22 changes: 9 additions & 13 deletions DependencyInjection/Configuration.php
Expand Up @@ -52,16 +52,14 @@ public function getConfigTreeBuilder()
->arrayNode('resolvers')
->useAttributeAsKey('name')
->prototype('array')
->performNoDeepMerging()
;
->performNoDeepMerging();
$this->addResolversSections($resolversPrototypeNode);

$loadersPrototypeNode = $rootNode
->children()
->arrayNode('loaders')
->useAttributeAsKey('name')
->prototype('array')
;
->prototype('array');
$this->addLoadersSections($loadersPrototypeNode);

$rootNode
Expand All @@ -71,46 +69,44 @@ public function getConfigTreeBuilder()
empty($v['loaders']) ||
empty($v['loaders']['default']) ||
empty($v['resolvers']) ||
empty($v['resolvers']['default'])
;
empty($v['resolvers']['default']);
})
->then(function ($v) {
if (empty($v['loaders'])) {
$v['loaders'] = [];
}

if (false == is_array($v['loaders'])) {
if (false === is_array($v['loaders'])) {
throw new \LogicException('Loaders has to be array');
}

if (false == array_key_exists('default', $v['loaders'])) {
if (false === array_key_exists('default', $v['loaders'])) {
$v['loaders']['default'] = ['filesystem' => null];
}

if (empty($v['resolvers'])) {
$v['resolvers'] = [];
}

if (false == is_array($v['resolvers'])) {
if (false === is_array($v['resolvers'])) {
throw new \LogicException('Resolvers has to be array');
}

if (false == array_key_exists('default', $v['resolvers'])) {
if (false === array_key_exists('default', $v['resolvers'])) {
$v['resolvers']['default'] = ['web_path' => null];
}

return $v;
})
->end()
;
->end();

$rootNode
->fixXmlConfig('filter_set', 'filter_sets')
->children()
->scalarNode('driver')->defaultValue('gd')
->validate()
->ifTrue(function ($v) {
return !in_array($v, ['gd', 'imagick', 'gmagick']);
return !in_array($v, ['gd', 'imagick', 'gmagick'], true);
})
->thenInvalid('Invalid imagine driver specified: %s')
->end()
Expand Down
Expand Up @@ -55,7 +55,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
->beforeNormalization()
->ifString()
->then(function ($value) {
return array($value);
return [$value];
})
->end()
->treatNullLike([])
Expand Down Expand Up @@ -103,7 +103,7 @@ private function resolveDataRoots(array $staticPaths, array $config, ContainerBu
$resourcePaths = [];

foreach ($this->getBundleResourcePaths($container) as $name => $path) {
if (('whitelist' === $config['access_control_type']) === in_array($name, $config['access_control_list']) && is_dir($path)) {
if (('whitelist' === $config['access_control_type']) === in_array($name, $config['access_control_list'], true) && is_dir($path)) {
$resourcePaths[$name] = $path;
}
}
Expand Down
76 changes: 37 additions & 39 deletions Imagine/Cache/CacheManager.php
Expand Up @@ -91,40 +91,6 @@ public function addResolver($filter, ResolverInterface $resolver)
}
}

/**
* Gets a resolver for the given filter.
*
* In case there is no specific resolver, but a default resolver has been configured, the default will be returned.
*
* @param string $filter
* @param string $resolver
*
* @throws \OutOfBoundsException If neither a specific nor a default resolver is available
*
* @return ResolverInterface
*/
protected function getResolver($filter, $resolver)
{
// BC
if (!$resolver) {
$config = $this->filterConfig->get($filter);

$resolverName = empty($config['cache']) ? $this->defaultResolver : $config['cache'];
} else {
$resolverName = $resolver;
}

if (!isset($this->resolvers[$resolverName])) {
throw new \OutOfBoundsException(sprintf(
'Could not find resolver "%s" for "%s" filter type',
$resolverName,
$filter
));
}

return $this->resolvers[$resolverName];
}

/**
* Gets filtered path for rendering in the browser.
* It could be the cached one or an url of filter action.
Expand All @@ -143,14 +109,12 @@ public function getBrowserPath($path, $filter, array $runtimeConfig = [], $resol

return $this->isStored($rcPath, $filter, $resolver) ?
$this->resolve($rcPath, $filter, $resolver) :
$this->generateUrl($path, $filter, $runtimeConfig, $resolver)
;
$this->generateUrl($path, $filter, $runtimeConfig, $resolver);
}

return $this->isStored($path, $filter, $resolver) ?
$this->resolve($path, $filter, $resolver) :
$this->generateUrl($path, $filter, [], $resolver)
;
$this->generateUrl($path, $filter, [], $resolver);
}

/**
Expand Down Expand Up @@ -226,7 +190,7 @@ public function isStored($path, $filter, $resolver = null)
*/
public function resolve($path, $filter, $resolver = null)
{
if (false !== strpos($path, '/../') || 0 === strpos($path, '../')) {
if (false !== mb_strpos($path, '/../') || 0 === mb_strpos($path, '../')) {
throw new NotFoundHttpException(sprintf("Source image was searched with '%s' outside of the defined root path", $path));
}

Expand Down Expand Up @@ -287,4 +251,38 @@ public function remove($paths = null, $filters = null)
$resolver->remove($paths, $mapping[$resolver]);
}
}

/**
* Gets a resolver for the given filter.
*
* In case there is no specific resolver, but a default resolver has been configured, the default will be returned.
*
* @param string $filter
* @param string $resolver
*
* @throws \OutOfBoundsException If neither a specific nor a default resolver is available
*
* @return ResolverInterface
*/
protected function getResolver($filter, $resolver)
{
// BC
if (!$resolver) {
$config = $this->filterConfig->get($filter);

$resolverName = empty($config['cache']) ? $this->defaultResolver : $config['cache'];
} else {
$resolverName = $resolver;
}

if (!isset($this->resolvers[$resolverName])) {
throw new \OutOfBoundsException(sprintf(
'Could not find resolver "%s" for "%s" filter type',
$resolverName,
$filter
));
}

return $this->resolvers[$resolverName];
}
}

0 comments on commit 248d9f1

Please sign in to comment.