Skip to content

codestyle: adjust to symfony default ruleset #454

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 3 commits into from
Oct 22, 2020
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
6 changes: 3 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
############################################################################
# This file is part of the Symfony CMF package. #
# #
# (c) 2011-2017 Symfony CMF #
# (c) Symfony CMF i #
# #
# For the full copyright and license information, please view the LICENSE #
# file that was distributed with this source code. #
Expand All @@ -16,10 +16,10 @@

preset: symfony

risky: true

enabled:
- combine_consecutive_unsets
- short_array_syntax
- newline_after_open_tag
- no_php4_constructor
- no_useless_else
- ordered_use
Expand Down
7 changes: 0 additions & 7 deletions src/CmfRoutingBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
*/
class CmfRoutingBundle extends Bundle
{
/**
* @param ContainerBuilder $container
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
Expand All @@ -52,8 +49,6 @@ public function build(ContainerBuilder $container)
/**
* Creates and registers compiler passes for PHPCR-ODM mapping if both the
* phpcr-odm and the phpcr-bundle are present.
*
* @param ContainerBuilder $container
*/
private function buildPhpcrCompilerPass(ContainerBuilder $container)
{
Expand All @@ -80,8 +75,6 @@ private function buildPhpcrCompilerPass(ContainerBuilder $container)
/**
* Creates and registers compiler passes for ORM mappings if both doctrine
* ORM and a suitable compiler pass implementation are available.
*
* @param ContainerBuilder $container
*/
private function buildOrmCompilerPass(ContainerBuilder $container)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Controller/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function __construct(RouterInterface $router)
/**
* Action to redirect based on a RedirectRouteInterface route.
*
* @param RedirectRouteInterface $contentDocument
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse the response
*/
public function redirectAction(RedirectRouteInterface $contentDocument)
Expand Down
14 changes: 7 additions & 7 deletions src/DependencyInjection/CmfRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function setupFormTypes(array $config, ContainerBuilder $container, Load
{
$loader->load('form-type.xml');

if (array_key_exists('dynamic', $config)) {
if (\array_key_exists('dynamic', $config)) {
$routeTypeTypeDefinition = $container->getDefinition('cmf_routing.route_type_form_type');

foreach (array_keys($config['dynamic']['controllers_by_type']) as $routeType) {
Expand Down Expand Up @@ -94,7 +94,7 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
$container->setParameter('cmf_routing.default_controller', $defaultController);

$locales = $config['locales'];
if (0 === count($locales) && $config['auto_locale_pattern']) {
if (0 === \count($locales) && $config['auto_locale_pattern']) {
throw new InvalidConfigurationException('It makes no sense to activate auto_locale_pattern when no locales are configured.');
}

Expand Down Expand Up @@ -148,17 +148,17 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
$dynamic = $container->getDefinition('cmf_routing.dynamic_router');

// if any mappings are defined, set the respective route enhancer
if (count($config['controllers_by_type']) > 0) {
if (\count($config['controllers_by_type']) > 0) {
$container->getDefinition('cmf_routing.enhancer.controllers_by_type')
->addTag('dynamic_router_route_enhancer', ['priority' => 60]);
}

if (count($config['controllers_by_class']) > 0) {
if (\count($config['controllers_by_class']) > 0) {
$container->getDefinition('cmf_routing.enhancer.controllers_by_class')
->addTag('dynamic_router_route_enhancer', ['priority' => 50]);
}

if (count($config['templates_by_class']) > 0) {
if (\count($config['templates_by_class']) > 0) {
$container->getDefinition('cmf_routing.enhancer.templates_by_class')
->addTag('dynamic_router_route_enhancer', ['priority' => 40]);

Expand Down Expand Up @@ -197,7 +197,7 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
->addTag('dynamic_router_route_enhancer', ['priority' => -100]);
}

if (count($config['route_filters_by_id']) > 0) {
if (\count($config['route_filters_by_id']) > 0) {
$matcher = $container->getDefinition('cmf_routing.nested_matcher');

foreach ($config['route_filters_by_id'] as $id => $priority) {
Expand All @@ -217,7 +217,7 @@ private function loadPhpcrProvider(array $config, LoaderInterface $loader, Conta

$container->setParameter('cmf_routing.dynamic.persistence.phpcr.manager_name', $config['manager_name']);

if (0 === count($locales)) {
if (0 === \count($locales)) {
$container->removeDefinition('cmf_routing.phpcrodm_route_locale_listener');
} elseif (!$matchImplicitLocale) {
// remove all but the prefixes configuration from the service definition.
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function addDynamicSection(ArrayNodeDefinition $root)
->addDefaultsIfNotSet()
->validate()
->ifTrue(function ($v) {
return count(array_filter($v, function ($persistence) {
return \count(array_filter($v, function ($persistence) {
return $persistence['enabled'];
})) > 1;
})
Expand Down
3 changes: 1 addition & 2 deletions src/Doctrine/DoctrineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ abstract class DoctrineProvider
protected $routeCollectionLimit;

/**
* @param ManagerRegistry $managerRegistry
* @param string $className
* @param string $className
*/
public function __construct(ManagerRegistry $managerRegistry, $className = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Doctrine/Orm/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public function findById($id)
*/
public function getContentId($content)
{
if (!is_object($content)) {
if (!\is_object($content)) {
return;
}

try {
$class = get_class($content);
$class = \get_class($content);
$meta = $this->getObjectManager()->getClassMetadata($class);
$ids = $meta->getIdentifierValues($content);
if (1 !== count($ids)) {
if (1 !== \count($ids)) {
throw new \Exception(sprintf('Class "%s" must use only one identifier', $class));
}

Expand Down
6 changes: 2 additions & 4 deletions src/Doctrine/Orm/RedirectRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class RedirectRoute extends RedirectRouteModel
* Additional options:
*
* * add_trailing_slash: When set, a trailing slash is appended to the route
*
* @param array $options
*/
public function __construct(array $options = [])
{
Expand Down Expand Up @@ -74,7 +72,7 @@ public function getParameters()
{
$params = json_decode($this->serialisedParameters);

return is_array($params) ? $params : [];
return \is_array($params) ? $params : [];
}

/**
Expand All @@ -83,7 +81,7 @@ public function getParameters()
public function getPath()
{
$pattern = parent::getPath();
if ($this->getOption('add_trailing_slash') && '/' !== $pattern[strlen($pattern) - 1]) {
if ($this->getOption('add_trailing_slash') && '/' !== $pattern[\strlen($pattern) - 1]) {
$pattern .= '/';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Orm/RouteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getRouteCollectionForRequest(Request $request)
$collection = new RouteCollection();

$candidates = $this->candidatesStrategy->getCandidates($request);
if (0 === count($candidates)) {
if (0 === \count($candidates)) {
return $collection;
}
$routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']);
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Phpcr/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function findById($id)
*/
public function getContentId($content)
{
if (!is_object($content)) {
if (!\is_object($content)) {
return;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Doctrine/Phpcr/IdPrefixListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class IdPrefixListener
/**
* This listener only makes sense together with the PrefixCandidates
* strategy.
*
* @param PrefixCandidates $candidates
*/
public function __construct(PrefixCandidates $candidates)
{
Expand Down
10 changes: 1 addition & 9 deletions src/Doctrine/Phpcr/LocaleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public function __construct(

/**
* Specify the list of allowed locales.
*
* @param array $locales
*/
public function setLocales(array $locales)
{
Expand All @@ -113,8 +111,6 @@ public function setUpdateAvailableTranslations($update)

/**
* Update locale after loading a route.
*
* @param LifecycleEventArgs $args
*/
public function postLoad(LifecycleEventArgs $args)
{
Expand All @@ -127,8 +123,6 @@ public function postLoad(LifecycleEventArgs $args)

/**
* Update locale after persisting a route.
*
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
Expand All @@ -141,8 +135,6 @@ public function postPersist(LifecycleEventArgs $args)

/**
* Update a locale after the route has been moved.
*
* @param MoveEventArgs $args
*/
public function postMove(MoveEventArgs $args)
{
Expand Down Expand Up @@ -184,7 +176,7 @@ protected function updateLocale(ModelRoute $doc, $id, DocumentManager $dm, $forc
return;
}

if (in_array($locale = $matches[2], $this->locales)) {
if (\in_array($locale = $matches[2], $this->locales)) {
if ($force || !$doc->getDefault('_locale')) {
$doc->setDefault('_locale', $locale);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Doctrine/Phpcr/PrefixCandidates.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function isCandidate($name)
public function restrictQuery($queryBuilder)
{
$prefixes = $this->getPrefixes();
if (in_array('', $prefixes) || !count($prefixes)) {
if (\in_array('', $prefixes) || !\count($prefixes)) {
return;
}

Expand All @@ -110,7 +110,7 @@ public function getCandidates(Request $request)

$locale = $this->determineLocale($url);
if ($locale) {
$url = substr($url, strlen($locale) + 1);
$url = substr($url, \strlen($locale) + 1);
foreach ($this->getPrefixes() as $prefix) {
$candidates = array_unique(array_merge($candidates, $this->getCandidatesFor($url, $prefix)));
}
Expand Down Expand Up @@ -174,12 +174,12 @@ public function setManagerName($manager)
protected function isCandidateValid($candidate)
{
// Candidates cannot start or end with a space in Jackrabbit.
if (' ' === \substr($candidate, 0, 1) || ' ' === \substr($candidate, -1)) {
if (' ' === substr($candidate, 0, 1) || ' ' === substr($candidate, -1)) {
return false;
}

// Jackrabbit does not allow spaces before or after the path separator.
if (false !== \strpos($candidate, ' /') || false !== \strpos($candidate, '/ ')) {
if (false !== strpos($candidate, ' /') || false !== strpos($candidate, '/ ')) {
return false;
}

Expand Down
6 changes: 2 additions & 4 deletions src/Doctrine/Phpcr/RedirectRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class RedirectRoute extends RedirectRouteModel implements PrefixInterface, Hiera
* Additional options:
*
* * add_trailing_slash: When set, a trailing slash is appended to the route
*
* @param array $options
*/
public function __construct(array $options = [])
{
Expand Down Expand Up @@ -222,7 +220,7 @@ public function generateStaticPrefix($id, $idPrefix)
throw new \LogicException("The id prefix '$idPrefix' does not match the route document path '$id'");
}

$url = substr($id, strlen($idPrefix));
$url = substr($id, \strlen($idPrefix));
if ('' === $url) {
$url = '/';
}
Expand All @@ -236,7 +234,7 @@ public function generateStaticPrefix($id, $idPrefix)
public function getPath()
{
$pattern = parent::getPath();
if ($this->getOption('add_trailing_slash') && '/' !== $pattern[strlen($pattern) - 1]) {
if ($this->getOption('add_trailing_slash') && '/' !== $pattern[\strlen($pattern) - 1]) {
$pattern .= '/';
}

Expand Down
12 changes: 6 additions & 6 deletions src/Doctrine/Phpcr/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function __construct(array $options = [])
*/
public function setParentDocument($parent)
{
if (!is_object($parent)) {
throw new InvalidArgumentException('Parent must be an object '.gettype($parent).' given.');
if (!\is_object($parent)) {
throw new InvalidArgumentException('Parent must be an object '.\gettype($parent).' given.');
}

$this->parent = $parent;
Expand Down Expand Up @@ -159,8 +159,8 @@ public function getName()
*/
public function setPosition($parent, $name)
{
if (!is_object($parent)) {
throw new InvalidArgumentException('Parent must be an object '.gettype($parent).' given.');
if (!\is_object($parent)) {
throw new InvalidArgumentException('Parent must be an object '.\gettype($parent).' given.');
}

$this->parent = $parent;
Expand Down Expand Up @@ -239,7 +239,7 @@ public function generateStaticPrefix($id, $idPrefix)
throw new \LogicException("The id prefix '$idPrefix' does not match the route document path '$id'");
}

$url = substr($id, strlen($idPrefix));
$url = substr($id, \strlen($idPrefix));
if (!$url) {
$url = '/';
}
Expand All @@ -255,7 +255,7 @@ public function generateStaticPrefix($id, $idPrefix)
public function getPath()
{
$pattern = parent::getPath();
if ($this->getOption('add_trailing_slash') && '/' !== $pattern[strlen($pattern) - 1]) {
if ($this->getOption('add_trailing_slash') && '/' !== $pattern[\strlen($pattern) - 1]) {
$pattern .= '/';
}

Expand Down
4 changes: 1 addition & 3 deletions src/Doctrine/Phpcr/RouteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public function __construct(
}

/**
* @param Request $request
*
* @return array a list of PHPCR-ODM ids
*/
public function getCandidates(Request $request)
Expand Down Expand Up @@ -88,7 +86,7 @@ public function getRouteCollectionForRequest(Request $request)

$collection = new RouteCollection();

if (0 === count($candidates)) {
if (0 === \count($candidates)) {
return $collection;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Doctrine/RouteConditionMetadataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function getSubscribedEvents()
/**
* Handle the load class metadata event: remove translated attribute from
* fields and remove the locale mapping if present.
*
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
Expand Down Expand Up @@ -71,7 +69,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
'nullable' => true,
]);
} else {
throw new \LogicException(sprintf('Class metadata was neither PHPCR nor ORM but %s', get_class($meta)));
throw new \LogicException(sprintf('Class metadata was neither PHPCR nor ORM but %s', \get_class($meta)));
}
}
}
Loading