Skip to content

Commit

Permalink
Applied fixes from FlintCI (#5218)
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh authored and greg0ire committed Sep 4, 2018
1 parent 1a40728 commit 03cd0ea
Show file tree
Hide file tree
Showing 70 changed files with 210 additions and 211 deletions.
2 changes: 1 addition & 1 deletion src/Action/AppendFormFieldElementAction.php
Expand Up @@ -85,7 +85,7 @@ public function __invoke(Request $request)

list(, $form) = $this->helper->appendFormFieldElement($admin, $subject, $elementId);

assert($form instanceof Form);
\assert($form instanceof Form);
$view = $this->helper->getChildFormView($form->createView(), $elementId);

// render the widget
Expand Down
14 changes: 7 additions & 7 deletions src/Action/RetrieveAutocompleteItemsAction.php
Expand Up @@ -104,20 +104,20 @@ public function __invoke(Request $request)
$datagrid = $targetAdmin->getDatagrid();

if (null !== $callback) {
if (!is_callable($callback)) {
if (!\is_callable($callback)) {
throw new \RuntimeException('Callback does not contain callable function.');
}

call_user_func($callback, $targetAdmin, $property, $searchText);
\call_user_func($callback, $targetAdmin, $property, $searchText);
} else {
if (is_array($property)) {
if (\is_array($property)) {
// multiple properties
foreach ($property as $prop) {
if (!$datagrid->hasFilter($prop)) {
throw new \RuntimeException(sprintf(
'To retrieve autocomplete items,'
.' you should add filter "%s" to "%s" in configureDatagridFilters() method.',
$prop, get_class($targetAdmin)
$prop, \get_class($targetAdmin)
));
}

Expand All @@ -132,7 +132,7 @@ public function __invoke(Request $request)
'To retrieve autocomplete items,'
.' you should add filter "%s" to "%s" in configureDatagridFilters() method.',
$property,
get_class($targetAdmin)
\get_class($targetAdmin)
));
}

Expand All @@ -151,11 +151,11 @@ public function __invoke(Request $request)

foreach ($results as $entity) {
if (null !== $toStringCallback) {
if (!is_callable($toStringCallback)) {
if (!\is_callable($toStringCallback)) {
throw new \RuntimeException('Option "to_string_callback" does not contain callable function.');
}

$label = call_user_func($toStringCallback, $entity, $property);
$label = \call_user_func($toStringCallback, $entity, $property);
} else {
$resultMetadata = $targetAdmin->getObjectMetadata($entity);
$label = $resultMetadata->getTitle();
Expand Down
4 changes: 2 additions & 2 deletions src/Action/SetObjectFieldValueAction.php
Expand Up @@ -45,7 +45,7 @@ public function __construct(Environment $twig, Pool $pool, $validator)
// NEXT_MAJOR: Move ValidatorInterface check to method signature
if (!($validator instanceof ValidatorInterface)) {
throw new \InvalidArgumentException(
'Argument 3 is an instance of '.get_class($validator).', expecting an instance of'
'Argument 3 is an instance of '.\get_class($validator).', expecting an instance of'
.' \Symfony\Component\Validator\Validator\ValidatorInterface'
);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public function __invoke(Request $request)

$violations = $this->validator->validate($object);

if (count($violations)) {
if (\count($violations)) {
$messages = [];

foreach ($violations as $violation) {
Expand Down
58 changes: 29 additions & 29 deletions src/Admin/AbstractAdmin.php
Expand Up @@ -827,7 +827,7 @@ public function getBaseRoutePattern()
preg_match(self::CLASS_REGEX, $this->class, $matches);

if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', get_class($this)));
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', \get_class($this)));
}
}

Expand All @@ -842,7 +842,7 @@ public function getBaseRoutePattern()
preg_match(self::CLASS_REGEX, $this->class, $matches);

if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', get_class($this)));
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', \get_class($this)));
}

$this->cachedBaseRoutePattern = sprintf('/%s%s/%s',
Expand Down Expand Up @@ -873,7 +873,7 @@ public function getBaseRouteName()
preg_match(self::CLASS_REGEX, $this->class, $matches);

if (!$matches) {
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', get_class($this)));
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
}
}

Expand All @@ -887,7 +887,7 @@ public function getBaseRouteName()
preg_match(self::CLASS_REGEX, $this->class, $matches);

if (!$matches) {
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', get_class($this)));
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
}

$this->cachedBaseRouteName = sprintf('admin_%s%s_%s',
Expand Down Expand Up @@ -917,7 +917,7 @@ public function getClass()
}

// see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4
if ($this->subject && is_object($this->subject)) {
if ($this->subject && \is_object($this->subject)) {
return ClassUtils::getClass($this->subject);
}

Expand All @@ -939,7 +939,7 @@ public function addSubClass($subClass): void
__METHOD__
), E_USER_DEPRECATED);

if (!in_array($subClass, $this->subClasses)) {
if (!\in_array($subClass, $this->subClasses)) {
$this->subClasses[] = $subClass;
}
}
Expand All @@ -956,7 +956,7 @@ public function hasSubClass($name)

public function hasActiveSubClass()
{
if (count($this->subClasses) > 0 && $this->request) {
if (\count($this->subClasses) > 0 && $this->request) {
return null !== $this->getRequest()->query->get('subclass');
}

Expand Down Expand Up @@ -1225,7 +1225,7 @@ public function getList()

public function createQuery($context = 'list')
{
if (func_num_args() > 0) {
if (\func_num_args() > 0) {
@trigger_error(
'The $context argument of '.__METHOD__.' is deprecated since 3.3, to be removed in 4.0.',
E_USER_DEPRECATED
Expand Down Expand Up @@ -1482,15 +1482,15 @@ public function hasParentFieldDescription()

public function setSubject($subject): void
{
if (is_object($subject) && !is_a($subject, $this->getClass(), true)) {
if (\is_object($subject) && !is_a($subject, $this->getClass(), true)) {
$message = <<<'EOT'
You are trying to set entity an instance of "%s",
which is not the one registered with this admin class ("%s").
This is deprecated since 3.5 and will no longer be supported in 4.0.
EOT;

@trigger_error(
sprintf($message, get_class($subject), $this->getClass()),
sprintf($message, \get_class($subject), $this->getClass()),
E_USER_DEPRECATED
); // NEXT_MAJOR : throw an exception instead
}
Expand Down Expand Up @@ -1760,7 +1760,7 @@ public function isChild()
*/
public function hasChildren()
{
return count($this->children) > 0;
return \count($this->children) > 0;
}

public function setUniqid($uniqid): void
Expand Down Expand Up @@ -1792,8 +1792,8 @@ public function getPersistentParameters()
foreach ($this->getExtensions() as $extension) {
$params = $extension->getPersistentParameters($this);

if (!is_array($params)) {
throw new \RuntimeException(sprintf('The %s::getPersistentParameters must return an array', get_class($extension)));
if (!\is_array($params)) {
throw new \RuntimeException(sprintf('The %s::getPersistentParameters must return an array', \get_class($extension)));
}

$parameters = array_merge($parameters, $params);
Expand Down Expand Up @@ -1893,7 +1893,7 @@ public function getTranslationDomain()
*/
public function setTranslator(TranslatorInterface $translator): void
{
$args = func_get_args();
$args = \func_get_args();
if (isset($args[1]) && $args[1]) {
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
Expand Down Expand Up @@ -2220,7 +2220,7 @@ public function getRouteBuilder()

public function toString($object)
{
if (!is_object($object)) {
if (!\is_object($object)) {
return '';
}

Expand Down Expand Up @@ -2293,7 +2293,7 @@ public function getPagerType()
*/
public function determinedPerPageValue($perPage)
{
return in_array($perPage, $this->perPageOptions);
return \in_array($perPage, $this->perPageOptions);
}

public function isAclEnabled()
Expand Down Expand Up @@ -2346,7 +2346,7 @@ public function checkAccess($action, $object = null): void
));
}

if (!is_array($access[$action])) {
if (!\is_array($access[$action])) {
$access[$action] = [$access[$action]];
}

Expand All @@ -2368,7 +2368,7 @@ public function hasAccess($action, $object = null)
return false;
}

if (!is_array($access[$action])) {
if (!\is_array($access[$action])) {
$access[$action] = [$access[$action]];
}

Expand All @@ -2385,7 +2385,7 @@ final public function getActionButtons($action, $object = null)
{
$buttonList = [];

if (in_array($action, ['tree', 'show', 'edit', 'delete', 'list', 'batch'])
if (\in_array($action, ['tree', 'show', 'edit', 'delete', 'list', 'batch'])
&& $this->hasAccess('create')
&& $this->hasRoute('create')
) {
Expand All @@ -2394,7 +2394,7 @@ final public function getActionButtons($action, $object = null)
];
}

if (in_array($action, ['show', 'delete', 'acl', 'history'])
if (\in_array($action, ['show', 'delete', 'acl', 'history'])
&& $this->canAccessObject('edit', $object)
&& $this->hasRoute('edit')
) {
Expand All @@ -2403,7 +2403,7 @@ final public function getActionButtons($action, $object = null)
];
}

if (in_array($action, ['show', 'edit', 'acl'])
if (\in_array($action, ['show', 'edit', 'acl'])
&& $this->canAccessObject('history', $object)
&& $this->hasRoute('history')
) {
Expand All @@ -2412,7 +2412,7 @@ final public function getActionButtons($action, $object = null)
];
}

if (in_array($action, ['edit', 'history'])
if (\in_array($action, ['edit', 'history'])
&& $this->isAclEnabled()
&& $this->canAccessObject('acl', $object)
&& $this->hasRoute('acl')
Expand All @@ -2422,17 +2422,17 @@ final public function getActionButtons($action, $object = null)
];
}

if (in_array($action, ['edit', 'history', 'acl'])
if (\in_array($action, ['edit', 'history', 'acl'])
&& $this->canAccessObject('show', $object)
&& count($this->getShow()) > 0
&& \count($this->getShow()) > 0
&& $this->hasRoute('show')
) {
$buttonList['show'] = [
'template' => $this->getTemplateRegistry()->getTemplate('button_show'),
];
}

if (in_array($action, ['show', 'edit', 'delete', 'acl', 'batch'])
if (\in_array($action, ['show', 'edit', 'delete', 'acl', 'batch'])
&& $this->hasAccess('list')
&& $this->hasRoute('list')
) {
Expand Down Expand Up @@ -2677,7 +2677,7 @@ protected function buildList(): void

$mapper = new ListMapper($this->getListBuilder(), $this->list, $this);

if (count($this->getBatchActions()) > 0) {
if (\count($this->getBatchActions()) > 0) {
$fieldDescription = $this->getModelManager()->getNewFieldDescriptionInstance(
$this->getClass(),
'batch',
Expand Down Expand Up @@ -2745,7 +2745,7 @@ protected function buildForm(): void

$value = $propertyAccessor->getValue($object, $propertyPath);

if (is_array($value) || ($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
if (\is_array($value) || ($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
$value[] = $parent;
$propertyAccessor->setValue($object, $propertyPath, $value);
} else {
Expand Down Expand Up @@ -2777,7 +2777,7 @@ protected function getSubClass($name)
throw new \RuntimeException(sprintf(
'Unable to find the subclass `%s` for admin `%s`',
$name,
get_class($this)
\get_class($this)
));
}

Expand Down Expand Up @@ -2869,7 +2869,7 @@ private function buildDatagrid(): void
$filterParameters = $this->getFilterParameters();

// transform _sort_by from a string to a FieldDescriptionInterface for the datagrid.
if (isset($filterParameters['_sort_by']) && is_string($filterParameters['_sort_by'])) {
if (isset($filterParameters['_sort_by']) && \is_string($filterParameters['_sort_by'])) {
if ($this->hasListFieldDescription($filterParameters['_sort_by'])) {
$filterParameters['_sort_by'] = $this->getListFieldDescription($filterParameters['_sort_by']);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/Admin/AdminHelper.php
Expand Up @@ -150,8 +150,8 @@ public function appendFormFieldElement(AdminInterface $admin, $subject, $element
$data[$childFormBuilder->getName()] = [];
}

$objectCount = null === $value ? 0 : count($value);
$postCount = count($data[$childFormBuilder->getName()]);
$objectCount = null === $value ? 0 : \count($value);
$postCount = \count($data[$childFormBuilder->getName()]);

$fields = array_keys($fieldDescription->getAssociationAdmin()->getFormFieldDescriptions());

Expand Down Expand Up @@ -263,7 +263,7 @@ protected function getEntityClassName(AdminInterface $admin, $elements)
{
$element = array_shift($elements);
$associationAdmin = $admin->getFormFieldDescription($element)->getAssociationAdmin();
if (0 == count($elements)) {
if (0 == \count($elements)) {
return $associationAdmin->getClass();
}

Expand Down

0 comments on commit 03cd0ea

Please sign in to comment.