Skip to content

Commit

Permalink
Merge pull request #2464 from acrobat/admin-bundle-code-improvements
Browse files Browse the repository at this point in the history
[AdminBundle] Code improvement found by static code analysis
  • Loading branch information
acrobat committed Jan 10, 2020
2 parents 01bb1d6 + d541ff5 commit 2196f14
Show file tree
Hide file tree
Showing 45 changed files with 93 additions and 105 deletions.
14 changes: 6 additions & 8 deletions src/Kunstmaan/AdminBundle/Command/ApplyAclCommand.php
Expand Up @@ -98,14 +98,12 @@ private function isRunning()
// Check if we have records in running state, if so read PID & check if process is active
/* @var AclChangeset $runningAclChangeset */
$runningAclChangeset = $this->em->getRepository('KunstmaanAdminBundle:AclChangeset')->findRunningChangeset();
if (!is_null($runningAclChangeset)) {
// Found running process, check if PID is still running
if (!$this->shellHelper->isRunning($runningAclChangeset->getPid())) {
// PID not running, process probably failed...
$runningAclChangeset->setStatus(AclChangeset::STATUS_FAILED);
$this->em->persist($runningAclChangeset);
$this->em->flush($runningAclChangeset);
}
// Found running process, check if PID is still running
if (!\is_null($runningAclChangeset) && !$this->shellHelper->isRunning($runningAclChangeset->getPid())) {
// PID not running, process probably failed...
$runningAclChangeset->setStatus(AclChangeset::STATUS_FAILED);
$this->em->persist($runningAclChangeset);
$this->em->flush();
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Command/CreateUserCommand.php
Expand Up @@ -269,7 +269,7 @@ protected function interact(InputInterface $input, OutputInterface $output)

// Validate that the chosen group options exist in the available groups
$groupNames = array_unique(explode(',', $groupsInput));
if (count(array_intersect_key(array_flip($groupNames), $this->groups)) !== count($groupNames)) {
if (\count(array_intersect_key(array_flip($groupNames), $this->groups)) !== \count($groupNames)) {
throw new InvalidArgumentException('You have chosen non existing group(s)');
}

Expand Down
3 changes: 1 addition & 2 deletions src/Kunstmaan/AdminBundle/Command/UpdateAclCommand.php
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;

/**
Expand Down Expand Up @@ -100,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->aclManager->updateNodesAclToRole($nodes, $role, $mask);

$output->writeln(count($nodes) . ' nodes processed.');
$output->writeln(\count($nodes) . ' nodes processed.');

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Controller/DefaultController.php
Expand Up @@ -60,7 +60,7 @@ public function editIndexAction(Request $request)
->getRepository('KunstmaanAdminBundle:DashboardConfiguration')
->findOneBy(array());

if (is_null($dashboardConfiguration)) {
if (\is_null($dashboardConfiguration)) {
$dashboardConfiguration = new DashboardConfiguration();
}
$form = $this->createForm(DashboardConfigurationType::class, $dashboardConfiguration);
Expand Down
Expand Up @@ -37,10 +37,10 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

if (array_key_exists('dashboard_route', $config)) {
if (\array_key_exists('dashboard_route', $config)) {
$container->setParameter('kunstmaan_admin.dashboard_route', $config['dashboard_route']);
}
if (array_key_exists('admin_password', $config)) {
if (\array_key_exists('admin_password', $config)) {
$container->setParameter('kunstmaan_admin.admin_password', $config['admin_password']);
}
$container->setParameter('kunstmaan_admin.admin_locales', $config['admin_locales']);
Expand Down Expand Up @@ -78,7 +78,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('console_listener.yml');
}

if (0 !== count($config['menu_items'])) {
if (0 !== \count($config['menu_items'])) {
$this->addSimpleMenuAdaptor($container, $config['menu_items']);
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public function prepend(ContainerBuilder $container)
$monologConfig['handlers']['main']['level'] = 'debug';
$container->prependExtensionConfig('monolog', $monologConfig);

$twigConfig['paths'][] = ['value' => dirname(__DIR__).'/Resources/views', 'namespace' => 'FOSUser'];
$twigConfig['paths'][] = ['value' => \dirname(__DIR__).'/Resources/views', 'namespace' => 'FOSUser'];
$container->prependExtensionConfig('twig', $twigConfig);

// NEXT_MAJOR: Remove templating dependency
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Entity/BaseUser.php
Expand Up @@ -84,7 +84,7 @@ public function getGroupIds()
$groups = $this->groups;

$groupIds = array();
if (count($groups) > 0) {
if (\count($groups) > 0) {
/* @var $group GroupInterface */
foreach ($groups as $group) {
$groupIds[] = $group->getId();
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Entity/GroupPropertiesTrait.php
Expand Up @@ -232,7 +232,7 @@ public function setName($name)
*/
public function isGroupValid(ExecutionContextInterface $context)
{
if (!(count($this->getRoles()) > 0)) {
if (!(\count($this->getRoles()) > 0)) {
$context
->buildViolation('errors.group.selectone', array())
->atPath('rolesCollection')
Expand Down
Expand Up @@ -90,7 +90,7 @@ public function onKernelRequest($event)
*/
private function isAdminToken($providerKey, TokenInterface $token = null)
{
return is_callable([$token, 'getProviderKey']) && $token->getProviderKey() === $providerKey;
return \is_callable([$token, 'getProviderKey']) && $token->getProviderKey() === $providerKey;
}

/**
Expand Down
Expand Up @@ -50,7 +50,7 @@ private function logCommandError($command, $error)
{
$message = sprintf(
'%s: %s (uncaught error) at %s line %s while running console command `%s`',
get_class($error),
\get_class($error),
$error->getMessage(),
$error->getFile(),
$error->getLine(),
Expand Down
Expand Up @@ -56,7 +56,7 @@ private function logCommandError($command, $error)
{
$message = sprintf(
'%s: %s (uncaught error) at %s line %s while running console command `%s`',
get_class($error),
\get_class($error),
$error->getMessage(),
$error->getFile(),
$error->getLine(),
Expand Down
Expand Up @@ -59,12 +59,12 @@ public function onKernelException($event)
if ($exception instanceof HttpExceptionInterface) {
$uri = $request->getUri();

if (count($this->excludes) > 0) {
if (\count($this->excludes) > 0) {
$excludes = array_filter($this->excludes, function ($pattern) use ($uri) {
return preg_match($pattern, $uri);
});

if (count($excludes) > 0) {
if (\count($excludes) > 0) {
return;
}
}
Expand Down
Expand Up @@ -134,11 +134,11 @@ private function getIp(Request $request)
{
if (!$this->ip) {
$forwarded = $request->server->get('HTTP_X_FORWARDED_FOR');
if (strlen($forwarded) > 0) {
if (\strlen($forwarded) > 0) {
$parts = explode(',', $forwarded);
$parts = array_map('trim', $parts);
$parts = array_filter($parts);
if (count($parts) > 0) {
if (\count($parts) > 0) {
$ip = $parts[0];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Helper/AdminPanel/AdminPanel.php
Expand Up @@ -69,7 +69,7 @@ private function sortAdaptors()

if (isset($this->adaptors)) {
krsort($this->adaptors);
$this->sorted = call_user_func_array('array_merge', $this->adaptors);
$this->sorted = array_merge(...$this->adaptors);
}
}
}
3 changes: 1 addition & 2 deletions src/Kunstmaan/AdminBundle/Helper/AdminRouteHelper.php
Expand Up @@ -3,7 +3,6 @@
namespace Kunstmaan\AdminBundle\Helper;

use Kunstmaan\NodeBundle\Router\SlugRouter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
Expand Down Expand Up @@ -49,7 +48,7 @@ public function isAdminRoute($url)
preg_match(sprintf(self::$ADMIN_MATCH_REGEX, $this->adminKey), $url, $matches);

// Check if path is part of admin area
if (count($matches) === 0) {
if (\count($matches) === 0) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Kunstmaan/AdminBundle/Helper/CloneHelper.php
Expand Up @@ -40,12 +40,12 @@ public function __construct(EntityManager $em, EventDispatcherInterface $eventDi
public function deepCloneAndSave($entity)
{
$clonedEntity = clone $entity;
$this->eventDispatcher->dispatch(Events::DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity, $this->em));
$this->eventDispatcher->dispatch(Events::DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity));

$this->em->persist($clonedEntity);
$this->em->flush();

$this->eventDispatcher->dispatch(Events::POST_DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity, $this->em));
$this->eventDispatcher->dispatch(Events::POST_DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity));

return $clonedEntity;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Helper/DomainConfiguration.php
Expand Up @@ -57,7 +57,7 @@ public function __construct(/*ContainerInterface|RequestStack*/ $requestStack, $
public function getHost()
{
$request = $this->getMasterRequest();
$host = is_null($request) ? '' : $request->getHost();
$host = \is_null($request) ? '' : $request->getHost();

return $host;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Kunstmaan/AdminBundle/Helper/FormHelper.php
Expand Up @@ -21,7 +21,7 @@ public function hasRecursiveErrorMessages(FormView $formView)
{
$errors = $formView->vars['errors'];

if (is_object($errors) && $errors instanceof \Traversable) {
if (\is_object($errors) && $errors instanceof \Traversable) {
$errors = iterator_to_array($errors);
}

Expand Down Expand Up @@ -50,14 +50,14 @@ public function hasRecursiveErrorMessages(FormView $formView)
*/
public function getRecursiveErrorMessages($formViews, array &$errors = array())
{
if (is_array($formViews)) {
if (\is_array($formViews)) {
foreach ($formViews as $formView) {
$this->getRecursiveErrorMessages($formView, $errors);
}
} else {
$viewErrors = $formViews->vars['errors'];

if (is_object($viewErrors) && $viewErrors instanceof \Traversable) {
if (\is_object($viewErrors) && $viewErrors instanceof \Traversable) {
$viewErrors = iterator_to_array($viewErrors);
}

Expand Down
Expand Up @@ -111,7 +111,7 @@ public function getFormErrors(FormView $formView)
*/
protected function getFormHelper()
{
if (is_null($this->formHelper)) {
if (\is_null($this->formHelper)) {
$this->formHelper = new FormHelper();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Helper/FormWidgets/Tabs/Tab.php
Expand Up @@ -118,7 +118,7 @@ public function getFormErrors(FormView $formView)
*/
protected function getFormHelper()
{
if (is_null($this->formHelper)) {
if (\is_null($this->formHelper)) {
$this->formHelper = new FormHelper();
}

Expand Down
10 changes: 5 additions & 5 deletions src/Kunstmaan/AdminBundle/Helper/FormWidgets/Tabs/TabPane.php
Expand Up @@ -125,7 +125,7 @@ public function addTab(TabInterface $tab, $position = null)
$tab->setIdentifier($this->generateIdentifier($tab));
}

if (!is_null($position) && is_numeric($position) && $position < count($this->tabs)) {
if (!\is_null($position) && is_numeric($position) && $position < \count($this->tabs)) {
array_splice($this->tabs, $position, 0, array($tab));
} else {
$this->tabs[] = $tab;
Expand All @@ -141,7 +141,7 @@ public function addTab(TabInterface $tab, $position = null)
*/
public function removeTab(TabInterface $tab)
{
if (in_array($tab, $this->tabs)) {
if (\in_array($tab, $this->tabs)) {
unset($this->tabs[array_search($tab, $this->tabs)]);
$this->reindexTabs();
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public function removeTabByTitle($title)
*/
public function removeTabByPosition($position)
{
if (is_numeric($position) && $position < count($this->tabs)) {
if (is_numeric($position) && $position < \count($this->tabs)) {
array_splice($this->tabs, $position, 1);
}

Expand Down Expand Up @@ -213,7 +213,7 @@ public function getTabByTitle($title)
*/
public function getTabByPosition($position)
{
if (is_numeric($position) && $position < count($this->tabs)) {
if (is_numeric($position) && $position < \count($this->tabs)) {
return $this->tabs[$position];
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public function getForm()
*/
public function getFormView()
{
if (is_null($this->formView)) {
if (\is_null($this->formView)) {
$this->formView = $this->form->createView();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Kunstmaan/AdminBundle/Helper/Menu/MenuBuilder.php
Expand Up @@ -95,7 +95,7 @@ public function getBreadCrumb()
{
$result = array();
$current = $this->getCurrent();
while (!is_null($current)) {
while (!\is_null($current)) {
array_unshift($result, $current);
$current = $current->getParent();
}
Expand All @@ -111,7 +111,7 @@ public function getBreadCrumb()
public function getLowestTopChild()
{
$current = $this->getCurrent();
while (!is_null($current)) {
while (!\is_null($current)) {
if ($current instanceof TopMenuItem) {
return $current;
}
Expand All @@ -128,7 +128,7 @@ public function getLowestTopChild()
*/
public function getTopChildren()
{
if (is_null($this->topMenuItems)) {
if (\is_null($this->topMenuItems)) {
/* @var $request Request */
$request = $this->container->get('request_stack')->getCurrentRequest();
$this->topMenuItems = array();
Expand Down Expand Up @@ -180,7 +180,7 @@ private function sortAdaptors()

if (isset($this->adaptors)) {
krsort($this->adaptors);
$this->sorted = call_user_func_array('array_merge', $this->adaptors);
$this->sorted = array_merge(...$this->adaptors);
}
}
}
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Helper/Menu/MenuItem.php
Expand Up @@ -251,7 +251,7 @@ public function setRouteParams(array $routeParams = array())
*/
public function getChildren()
{
if (is_null($this->children)) {
if (\is_null($this->children)) {
$this->children = $this->menu->getChildren($this);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ class ModulesMenuAdaptor implements MenuAdaptorInterface
*/
public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
{
if (is_null($parent)) {
if (\is_null($parent)) {
$menuItem = new TopMenuItem($menu);
$menuItem
->setRoute('KunstmaanAdminBundle_modules')
Expand Down
4 changes: 2 additions & 2 deletions src/Kunstmaan/AdminBundle/Helper/Menu/SettingsMenuAdaptor.php
Expand Up @@ -42,7 +42,7 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker,
*/
public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
{
if (is_null($parent)) {
if (\is_null($parent)) {
$menuItem = new TopMenuItem($menu);
$menuItem
->setRoute('KunstmaanAdminBundle_settings')
Expand All @@ -56,7 +56,7 @@ public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $par
$children[] = $menuItem;
}

if (!is_null($parent) && 'KunstmaanAdminBundle_settings' == $parent->getRoute()) {
if (!\is_null($parent) && 'KunstmaanAdminBundle_settings' == $parent->getRoute()) {
if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN') && $this->isEnabledVersionChecker) {
$menuItem = new MenuItem($menu);
$menuItem
Expand Down

0 comments on commit 2196f14

Please sign in to comment.