Skip to content

Commit

Permalink
Merge pull request #2660 from acrobat/setup-phpstan
Browse files Browse the repository at this point in the history
[AllBundles] Integrate phpstan in travis build suite
  • Loading branch information
acrobat committed Jun 25, 2020
2 parents 92791c2 + bb283af commit eab2a6b
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -90,4 +90,10 @@ jobs:
- npm run buildGroundControlSkeleton
after_script: skip

# Code quality checks
- stage: Code quality
php: 7.4
env: PHPStan=true
script: vendor/bin/phpstan analyse --no-progress


4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -88,7 +88,9 @@
"matthiasnoback/symfony-dependency-injection-test": "^3.1",
"symfony/phpunit-bridge": "^4.3",
"phpunit/phpunit": "^7.5",
"friendsofphp/php-cs-fixer": "^2.13"
"friendsofphp/php-cs-fixer": "^2.13",
"phpstan/phpstan": "^0.12.18",
"phpstan/phpstan-doctrine": "^0.12.10"
},
"replace": {
"kunstmaan/admin-bundle": "self.version",
Expand Down
22 changes: 22 additions & 0 deletions phpstan.neon
@@ -0,0 +1,22 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon

parameters:
level: 1
paths:
- src

excludes_analyse:
- src/Kunstmaan/*/Tests/*
- src/Kunstmaan/*/vendor/*
- src/Kunstmaan/BehatBundle
- src/Kunstmaan/GeneratorBundle/Resources/SensioGeneratorBundle
- src/Kunstmaan/CacheBundle # Temporary excluded for full rework
# Excluded deprecated classes/files
- src/Kunstmaan/AdminBundle/Composer/ScriptHandler.php
- src/Kunstmaan/AdminBundle/EventListener/ConsoleExceptionListener.php

ignoreErrors:
# Ignore errors on unfound classes for old symfony version BC layers
- '#^Class Symfony\\Component\\Security\\Core\\Role\\RoleInterface not found\.\z#'
- '#Constructor of class Kunstmaan\\MediaBundle\\AdminList\\MediaAdminListConfigurator has an unused parameter \$mediaManager\.#' # Will be fixed in separate PR
3 changes: 3 additions & 0 deletions src/Kunstmaan/AdminBundle/Controller/ExceptionController.php
Expand Up @@ -12,6 +12,9 @@

class ExceptionController extends AdminListController
{
/** @var ExceptionAdminListConfigurator */
private $configurator;

private function getAdminListConfigurator()
{
if (!isset($this->configurator)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/Helper/AdminRouteHelper.php
Expand Up @@ -41,7 +41,7 @@ public function __construct($adminKey, RequestStack $requestStack)
*/
public function isAdminRoute($url)
{
if ($this->matchesPreviewRoute($url)) {
if ($this->matchesPreviewRoute()) {
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Kunstmaan/AdminBundle/Helper/FormWidgets/Tabs/TabPane.php
Expand Up @@ -46,6 +46,9 @@ class TabPane
*/
protected $formView;

/** @var Slugifier */
private $slugifier;

/**
* @param string $identifier The identifier
* @param Request $request The request
Expand Down
Expand Up @@ -87,6 +87,7 @@ public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissi
/* @var $token TokenInterface */
$token = $this->tokenStorage->getToken();
$userRoles = array();
$user = null;
if (!\is_null($token)) {
$user = $token->getUser();
if (method_exists($this->roleHierarchy, 'getReachableRoleNames')) {
Expand Down
Expand Up @@ -63,7 +63,7 @@ public function __construct(ContainerInterface $container, Cache $cache, $transl

// NEXT_MAJOR Add "Symfony\Contracts\Translation\TranslatorInterface" typehint when sf <4.4 support is removed.
if (!$translator instanceof TranslatorInterface && !$translator instanceof LegacyTranslatorInterface) {
throw new \InvalidArgumentException(sprintf('The "$translator" parameter should be instance of "%s" or "%s"', Symfony\Contracts\Translation\TranslatorInterface::class, LegacyTranslatorInterface::class));
throw new \InvalidArgumentException(sprintf('The "$translator" parameter should be instance of "%s" or "%s"', TranslatorInterface::class, LegacyTranslatorInterface::class));
}

$this->translator = $translator;
Expand Down
6 changes: 6 additions & 0 deletions src/Kunstmaan/AdminListBundle/AdminList/FieldAlias.php
Expand Up @@ -7,6 +7,12 @@
*/
class FieldAlias
{
/** @var string */
private $abbr;

/** @var string */
private $relation;

/**
* FieldAlias constructor.
*
Expand Down
Expand Up @@ -93,9 +93,10 @@ public function setTokenAction(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');

$code = urldecode($request->query->get('code'));
$codeParameter = $request->query->get('code');

if (isset($code)) {
if (null !== $codeParameter) {
$code = urldecode($codeParameter);
$clientHelper = $this->container->get('kunstmaan_dashboard.helper.google.client');
$configHelper = $this->container->get('kunstmaan_dashboard.helper.google.analytics.config');

Expand Down
Expand Up @@ -190,7 +190,7 @@ protected function updateRouting(
$prefix = $multilang ? '/{_locale}' : '';

$code = sprintf("%s:\n", strtolower($bundle->getName()) . '_' . strtolower($entityClass) . '_admin_list');
$code .= sprintf(" resource: '@%s/Controller/%sAdminListController.php'\n", $bundle->getName(), $entityClass, "'");
$code .= sprintf(" resource: '@%s/Controller/%sAdminListController.php'\n", $bundle->getName(), $entityClass);
$code .= " type: annotation\n";
$code .= sprintf(" prefix: %s/%s/%s/\n", $prefix, $adminKey, strtolower($entityClass));
if ($multilang) {
Expand Down
Expand Up @@ -203,7 +203,7 @@ function ($name) use ($generator, $bundlePath) {
* Ask for which sections pagepart configuration the end user wants to use for the different sections
*/
$this->assistant->writeLine(array("\nThe select page template consists of these contexts: " . implode(', ', $templateConfig['contexts'])));
$this->section = array();
$this->sections = array();
foreach ($templateConfig['contexts'] as $context) {
$question = "Which pagepart configuration would you like to use for the '$context' context";
$section = $this->askForSections($question, $this->bundle, false, $context);
Expand Down
Expand Up @@ -50,8 +50,6 @@ public function generateEntityRepositoryClass(string $entityClass, string $repos
public function writeEntityRepositoryClass($entityClass, $repositoryClass, $outputDirectory)
{
$classNameParts = explode('\\', $repositoryClass);
$repositoryClassName = end($classNameParts);
$this->repositoryName = $repositoryClassName;
$code = $this->generateEntityRepositoryClass($entityClass, $repositoryClass);

$path = $outputDirectory . DIRECTORY_SEPARATOR . 'Repository' . DIRECTORY_SEPARATOR . end($classNameParts) . '.php';
Expand Down
Expand Up @@ -33,6 +33,9 @@ class DomainConfiguration extends BaseDomainConfiguration
*/
protected $adminRouteHelper;

/** @var EntityManagerInterface */
private $em;

/**
* @param ContainerInterface|string $multilanguage
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Kunstmaan/NodeBundle/Helper/Menu/PageMenuAdaptor.php
Expand Up @@ -10,7 +10,6 @@
use Kunstmaan\AdminBundle\Helper\Menu\TopMenuItem;
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper;
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap;
use Kunstmaan\NodeBundle\Entity\Node;
use Kunstmaan\NodeBundle\Helper\NodeMenuItem;
use Kunstmaan\NodeBundle\Helper\PagesConfiguration;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -157,7 +156,6 @@ private function getTreeNodes(
$includeHiddenFromNav,
$rootNode
);
/** @var Node $nodeInfo */
foreach ($allNodes as $nodeInfo) {
$refEntityName = $nodeInfo['ref_entity_name'];
if ($this->pagesConfiguration->isHiddenFromTree($refEntityName)) {
Expand Down
5 changes: 3 additions & 2 deletions src/Kunstmaan/NodeBundle/Helper/NodeMenu.php
Expand Up @@ -485,6 +485,7 @@ function (Node $entry) use ($includeOffline) {
);

if (!\is_null($parent)) {
$parentNode = null;
/** @var Node $parentNode */
if ($parent instanceof NodeTranslation) {
$parentNode = $parent->getNode();
Expand All @@ -500,7 +501,7 @@ function (Node $entry) use ($includeOffline) {
// Look for a node with the same parent id
/** @var Node $node */
foreach ($nodes as $node) {
if ($node->getParent()->getId() == $parentNode->getId()) {
if ($parentNode && $node->getParent()->getId() == $parentNode->getId()) {
$resultNode = $node;

break;
Expand All @@ -516,7 +517,7 @@ function (Node $entry) use ($includeOffline) {
$tempNode->getParent()
)) {
$tempParent = $tempNode->getParent();
if ($tempParent->getId() == $parentNode->getId()) {
if ($parentNode && $tempParent->getId() == $parentNode->getId()) {
$resultNode = $node;

break;
Expand Down
Expand Up @@ -548,6 +548,7 @@ protected function addPageContent(NodeTranslation $nodeTranslation, $page, &$doc
*/
protected function enterRequestScope($lang)
{
$locale = null;
$requestStack = $this->container->get('request_stack');
// If there already is a request, get the locale from it.
if ($requestStack->getCurrentRequest()) {
Expand Down
Expand Up @@ -247,6 +247,7 @@ public function getQueryBuilder()

foreach ($this->locales as $key => $locale) {
$uniqueId = 'txt_'.$key;
$expr = null;
switch ($textComparator) {
case 'equals':
$expr = $this->queryBuilder->expr()->eq('t_'.$locale.'.`text`', ':var_'.$uniqueId);
Expand Down Expand Up @@ -287,7 +288,10 @@ public function getQueryBuilder()

break;
}
$orX->add($expr);

if (null !== $expr) {
$orX->add($expr);
}
}

$this->queryBuilder->andWhere($orX);
Expand Down
Expand Up @@ -2,13 +2,17 @@

namespace Kunstmaan\TranslatorBundle\Service\Translator;

use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;

/**
* Validates and checks translations cache
*/
class CacheValidator
{
/** @var LoggerInterface */
private $logger;

/**
* Where to store cache files
*
Expand Down

0 comments on commit eab2a6b

Please sign in to comment.