Skip to content

Commit

Permalink
Update php-cs-fixer and phpstan (#152)
Browse files Browse the repository at this point in the history
* Update php-cs-fixer

* Remove php-cs-fixer from PHP 7.2 pipeline

* Update phpstan

* Add phpstan baseline

* Add PHP 8.1 pipeline

* Fix php-cs

* Fix ci for removing php-cs-fixer/shim
  • Loading branch information
alexander-schranz authored Jul 25, 2022
1 parent f8f865c commit 0f96d4c
Show file tree
Hide file tree
Showing 67 changed files with 988 additions and 442 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '7.4'
lint: true
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
Expand All @@ -40,6 +40,13 @@ jobs:
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.1'
lint: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

services:
mysql:
image: mysql:5.7
Expand All @@ -60,6 +67,10 @@ jobs:
extensions: 'mysql, gd'
tools: ${{ matrix.tools }}

- name: Remove php-cs-fixer/shim package
if: ${{ matrix.php-version == '7.2' }}
run: composer remove php-cs-fixer/shim --dev --no-interaction

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# PHPCS
.php_cs.cache
.php-cs-fixer.cache

# composer
/composer.phar
Expand Down
55 changes: 55 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

$header = <<<EOF
This file is part of Sulu.
(c) Sulu GmbH
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

$finder = PhpCsFixer\Finder::create()
->exclude(['var/cache', 'var/coverage.php'])
->in(__DIR__);

$config = new PhpCsFixer\Config();
$config->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'ordered_imports' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'phpdoc_align' => ['align' => 'left'],
'class_definition' => [
'multi_line_extends_each_single_line' => true,
] ,
'linebreak_after_opening_tag' => true,
// 'declare_strict_types' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => ['include' => ['@internal']],
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
'array_indentation' => true,
'multiline_whitespace_before_semicolons' => true,
'single_line_throw' => false,
'visibility_required' => ['elements' => ['property', 'method', 'const']],
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var'],
],
'trailing_comma_in_multiline' => ['elements' => ['arrays', /*'arguments', 'parameters' */]],
])
->setFinder($finder);

return $config;
19 changes: 8 additions & 11 deletions Admin/CommunityAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
*/
class CommunityAdmin extends Admin
{
const BLACKLIST_ITEM_SECURITY_CONTEXT = 'sulu.community.blacklist_items';
const BLACKLIST_ITEM_LIST_VIEW = 'sulu_community.blacklist_item';
const BLACKLIST_ITEM_ADD_FORM_VIEW = 'sulu_community.blacklist_item.add_form';
const BLACKLIST_ITEM_EDIT_FORM_VIEW = 'sulu_community.blacklist_item.edit_form';
public const BLACKLIST_ITEM_SECURITY_CONTEXT = 'sulu.community.blacklist_items';
public const BLACKLIST_ITEM_LIST_VIEW = 'sulu_community.blacklist_item';
public const BLACKLIST_ITEM_ADD_FORM_VIEW = 'sulu_community.blacklist_item.add_form';
public const BLACKLIST_ITEM_EDIT_FORM_VIEW = 'sulu_community.blacklist_item.edit_form';

/**
* @var SecurityCheckerInterface
Expand Down Expand Up @@ -142,36 +142,33 @@ public function configureViews(ViewCollection $viewCollection): void
}
}

/**
* {@inheritdoc}
*/
public function getSecurityContexts()
{
$systems = [];

$webspaceCollection = $this->webspaceManager->getWebspaceCollection();

$webspaceKeys = array_keys($webspaceCollection->getWebspaces());
$webspaceKeys = \array_keys($webspaceCollection->getWebspaces());

foreach ($this->webspacesConfiguration as $webspaceKey => $webspaceConfig) {
$webspace = $webspaceCollection->getWebspace($webspaceKey);

if (!$webspace) {
throw new \InvalidArgumentException(sprintf('Webspace "%s" not found for "sulu_community" expected one of %s.', $webspaceKey, '"' . implode('", "', $webspaceKeys) . '"'));
throw new \InvalidArgumentException(\sprintf('Webspace "%s" not found for "sulu_community" expected one of %s.', $webspaceKey, '"' . \implode('", "', $webspaceKeys) . '"'));
}

/** @var Security|null $security */
$security = $webspace->getSecurity();

if (!$security) {
throw new \InvalidArgumentException(sprintf('Missing "<security><system>Website</system><security>" configuration in webspace "%s" for "sulu_community".', $webspaceKey));
throw new \InvalidArgumentException(\sprintf('Missing "<security><system>Website</system><security>" configuration in webspace "%s" for "sulu_community".', $webspaceKey));
}

$system = $security->getSystem();
$systems[$system] = [];
}

return array_merge(
return \array_merge(
$systems,
[
'Sulu' => [
Expand Down
5 changes: 0 additions & 5 deletions Build/CommunityBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@
*/
class CommunityBuilder extends SuluBuilder
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'community';
}

/**
* {@inheritdoc}
*
* @return string[]
*/
public function getDependencies(): array
Expand Down
15 changes: 5 additions & 10 deletions Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
class InitCommand extends Command
{
const NAME = 'sulu:community:init';
public const NAME = 'sulu:community:init';

/**
* @var EntityManagerInterface
Expand Down Expand Up @@ -66,18 +66,12 @@ public function __construct(
parent::__construct(self::NAME);
}

/**
* {@inheritdoc}
*/
public function configure(): void
{
$this->setDescription('Create the user roles for the community.')
->addArgument('webspace', null, 'A specific webspace key.');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var string|null $webspaceKey */
Expand All @@ -87,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);

if (!$webspace) {
throw new \InvalidArgumentException(sprintf('Given webspace "%s" is invalid', $webspaceKey));
throw new \InvalidArgumentException(\sprintf('Given webspace "%s" is invalid', $webspaceKey));
}

$this->initWebspace($webspace, $output);
Expand Down Expand Up @@ -122,12 +116,13 @@ private function initWebspace(Webspace $webspace, OutputInterface $output): void
}

$communityManager = $this->communityManagerRegistry->get($webspaceKey);
/** @var string $roleName */
$roleName = $communityManager->getConfigProperty(Configuration::ROLE);
$system = $security->getSystem();

// Create role if not exists
$output->writeln(
sprintf(
\sprintf(
$this->createRoleIfNotExists($roleName, $system, $webspaceKey),
$roleName,
$system
Expand Down Expand Up @@ -203,7 +198,7 @@ private function addPermissions(RoleInterface $role, string $system, string $web
}
}

if (0 === strpos($securityContext, 'sulu.webspaces.')
if (0 === \strpos($securityContext, 'sulu.webspaces.')
&& $webspaceSecurityContext !== $securityContext
) {
// Do not add permissions for other webspaces
Expand Down
23 changes: 11 additions & 12 deletions Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
abstract class AbstractController extends SymfonyAbstractController
{
/**
* @var string
* @var string|null
*/
private $webspaceKey;

Expand All @@ -52,7 +52,7 @@ protected function getCommunityManager(string $webspaceKey): CommunityManagerInt
protected function getWebspaceKey(): string
{
if (null === $this->webspaceKey) {
return $this->getRequestAnalyzer()->getWebspace()->getKey();
$this->webspaceKey = $this->getRequestAnalyzer()->getWebspace()->getKey();
}

return $this->webspaceKey;
Expand All @@ -63,6 +63,7 @@ protected function getWebspaceKey(): string
*/
protected function setUserPasswordAndSalt(User $user, FormInterface $form): User
{
/** @var string|null $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();
if (null === $plainPassword) {
return $user;
Expand All @@ -85,6 +86,7 @@ protected function setUserPasswordAndSalt(User $user, FormInterface $form): User
*/
protected function checkAutoLogin(string $type): bool
{
/** @var bool */
return $this->getCommunityManager($this->getWebspaceKey())->getConfigTypeProperty(
$type,
Configuration::AUTO_LOGIN
Expand All @@ -98,11 +100,14 @@ protected function checkAutoLogin(string $type): bool
*/
protected function renderTemplate(string $type, array $data = []): Response
{
/** @var string $template */
$template = $this->getCommunityManager($this->getWebspaceKey())->getConfigTypeProperty(
$type,
Configuration::TEMPLATE
);

return $this->render(
$this->getCommunityManager($this->getWebspaceKey())->getConfigTypeProperty(
$type,
Configuration::TEMPLATE
),
$template,
$data
);
}
Expand All @@ -128,8 +133,6 @@ private function getTemplateAttributes(array $custom = []): array
}

/**
* {@inheritdoc}
*
* @return User
*/
public function getUser(): ?User
Expand Down Expand Up @@ -170,8 +173,6 @@ private function addAddress(User $user): void
}

/**
* {@inheritdoc}
*
* @param mixed[] $parameters
*/
public function render(string $view, array $parameters = [], Response $response = null): Response
Expand All @@ -184,8 +185,6 @@ public function render(string $view, array $parameters = [], Response $response
}

/**
* {@inheritdoc}
*
* @param mixed[] $parameters
*/
public function renderView(string $view, array $parameters = []): string
Expand Down
16 changes: 11 additions & 5 deletions Controller/BlacklistConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class BlacklistConfirmationController extends AbstractController
*/
public function confirmAction(Request $request): Response
{
/** @var string $token */
$token = $request->get('token');

/** @var BlacklistUser|null $blacklistUser */
$blacklistUser = $this->getBlacklistUserRepository()->findByToken($request->get('token'));
$blacklistUser = $this->getBlacklistUserRepository()->findByToken($token);

if (null === $blacklistUser) {
throw new NotFoundHttpException();
Expand Down Expand Up @@ -62,8 +65,11 @@ public function denyAction(Request $request): Response
{
$entityManager = $this->getEntityManager();

/** @var string $token */
$token = $request->get('token');

/** @var BlacklistUser|null $blacklistUser */
$blacklistUser = $this->getBlacklistUserRepository()->findByToken($request->get('token'));
$blacklistUser = $this->getBlacklistUserRepository()->findByToken($token);

if (null === $blacklistUser) {
throw new NotFoundHttpException();
Expand All @@ -75,9 +81,9 @@ public function denyAction(Request $request): Response

$communityManager = $this->getCommunityManager($blacklistUser->getWebspaceKey());
if (true === $communityManager->getConfigTypeProperty(
Configuration::TYPE_BLACKLIST_DENIED,
Configuration::DELETE_USER
)
Configuration::TYPE_BLACKLIST_DENIED,
Configuration::DELETE_USER
)
) {
$entityManager->remove($user->getContact());
$entityManager->remove($user);
Expand Down
11 changes: 6 additions & 5 deletions Controller/BlacklistItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(
*/
public function fieldsAction(): Response
{
return $this->handleView($this->view(array_values($this->getFieldDescriptors()), 200));
return $this->handleView($this->view(\array_values($this->getFieldDescriptors()), 200));
}

/**
Expand Down Expand Up @@ -148,9 +148,9 @@ public function deleteAction(int $id): Response
*/
public function cdeleteAction(Request $request): Response
{
$ids = array_map(function($id) {
$ids = \array_map(function ($id) {
return (int) $id;
}, array_filter(explode(',', (string) $request->query->get('ids', ''))));
}, \array_filter(\explode(',', (string) $request->query->get('ids', ''))));

$this->blacklistItemManager->delete($ids);
$this->entityManager->flush();
Expand Down Expand Up @@ -222,9 +222,10 @@ private function getFieldDescriptors(): array
*/
private function prepareListResponse(Request $request, ListBuilderInterface $listBuilder, array $fieldDescriptors)
{
/** @var string $idsParameter */
$idsParameter = $request->get('ids');
$ids = array_filter(explode(',', $idsParameter));
if (null !== $idsParameter && 0 === count($ids)) {
$ids = \array_filter(\explode(',', $idsParameter));
if (null !== $idsParameter && 0 === \count($ids)) {
return [];
}

Expand Down
Loading

0 comments on commit 0f96d4c

Please sign in to comment.