Skip to content

Commit

Permalink
Upgrade php-cs-fixer (#194)
Browse files Browse the repository at this point in the history
* Upgrade php-cs-fixer

* Exclude php cs fixer file from code coverage

* Update composer json

* Fix php-cs

* Update rule order

* Update .php-cs-fixer.dist.php
  • Loading branch information
alexander-schranz authored Sep 14, 2021
1 parent d6b82d2 commit bd6674a
Show file tree
Hide file tree
Showing 80 changed files with 325 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/php-coveralls.phar

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

# System files
.DS_Store
Expand Down
31 changes: 14 additions & 17 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$header = <<<'EOF'
$header = <<<EOF
This file is part of Sulu.
(c) Sulu GmbH
Expand All @@ -9,33 +9,28 @@
with this source code in the file LICENSE.
EOF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
$config = new PhpCsFixer\Config();
$config->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'ordered_imports' => true,
'class_definition' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'phpdoc_align' => false,
'class_definition' => [
'multiLineExtendsEachSingleLine' => true,
],
'linebreak_after_opening_tag' => true,
'declare_strict_types' => true,
'mb_str_functions' => true,
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_unreachable_default_argument_value' => true,
'function_declaration' => ['closure_function_spacing' => 'none'],
'header_comment' => ['header' => $header],
'native_function_invocation' => ['include' => ['@internal']],
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true],
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_strict' => true,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_order' => true,
'strict_comparison' => true,
'strict_param' => true,
'phpdoc_to_comment' => false,
'header_comment' => ['header' => $header],
'phpdoc_types_order' => false,
'single_line_throw' => false,
'strict_comparison' => true,
'strict_param' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand All @@ -44,3 +39,5 @@
->exclude('Tests/reports/')
->in(__DIR__)
);

return $config;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function map(
DimensionContentCollectionInterface $dimensionContentCollection
): void {
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();
$unlocalizedDimensionAttributes = array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes);

if (!$unlocalizedObject instanceof AuthorInterface) {
Expand All @@ -45,7 +45,7 @@ public function map(

if ($localizedObject) {
if (!$localizedObject instanceof AuthorInterface) {
throw new \RuntimeException(sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', AuthorInterface::class, \get_class($localizedObject)));
throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', AuthorInterface::class, \get_class($localizedObject)));
}

$this->setAuthorData($localizedObject, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function map(
DimensionContentCollectionInterface $dimensionContentCollection
): void {
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();
$unlocalizedDimensionAttributes = array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes);

if (!$unlocalizedObject instanceof ExcerptInterface) {
Expand All @@ -52,7 +52,7 @@ public function map(

if ($localizedObject) {
if (!$localizedObject instanceof ExcerptInterface) {
throw new \RuntimeException(sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', ExcerptInterface::class, \get_class($localizedObject)));
throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', ExcerptInterface::class, \get_class($localizedObject)));
}

$this->setExcerptData($localizedObject, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function map(
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();
$localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes);

$unlocalizedDimensionAttributes = array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes);

if (!$localizedObject || !$localizedObject instanceof RoutableInterface) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public function map(
$routePath = $data[$name] ?? null;
if (!$routePath) {
/** @var mixed $routeGenerationData */
$routeGenerationData = array_merge(
$routeGenerationData = \array_merge(
$data,
[
'_unlocalizedObject' => $unlocalizedObject,
Expand Down Expand Up @@ -183,7 +183,7 @@ public function map(

if (($data[$name] ?? null) !== $route->getPath()) {
$localizedObject->setTemplateData(
array_merge(
\array_merge(
$localizedObject->getTemplateData(),
[$name => $route->getPath()]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function map(
DimensionContentCollectionInterface $dimensionContentCollection
): void {
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();
$unlocalizedDimensionAttributes = array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes);

if (!$unlocalizedObject instanceof SeoInterface) {
Expand All @@ -34,7 +34,7 @@ public function map(

if ($localizedObject) {
if (!$localizedObject instanceof SeoInterface) {
throw new \RuntimeException(sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', SeoInterface::class, \get_class($localizedObject)));
throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', SeoInterface::class, \get_class($localizedObject)));
}

$this->setSeoData($localizedObject, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function map(
DimensionContentCollectionInterface $dimensionContentCollection
): void {
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();
$unlocalizedDimensionAttributes = array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes);

if (!$unlocalizedObject instanceof TemplateInterface) {
Expand Down Expand Up @@ -73,7 +73,7 @@ public function map(

if ($localizedObject) {
if (!$localizedObject instanceof TemplateInterface) {
throw new \RuntimeException(sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', TemplateInterface::class, \get_class($localizedObject)));
throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', TemplateInterface::class, \get_class($localizedObject)));
}

$localizedObject->setTemplateKey($template);
Expand All @@ -86,7 +86,7 @@ public function map(
}

// Unlocalized dimensions can contain data of different templates so we need to merge them together
$unlocalizedObject->setTemplateData(array_merge(
$unlocalizedObject->setTemplateData(\array_merge(
$unlocalizedObject->getTemplateData(),
$unlocalizedData
));
Expand All @@ -102,7 +102,7 @@ private function getTemplateData(array $data, string $type, string $template): a
$metadata = $this->factory->getStructureMetadata($type, $template);

if (!$metadata) {
throw new \RuntimeException(sprintf('Could not find structure "%s" of type "%s".', $template, $type));
throw new \RuntimeException(\sprintf('Could not find structure "%s" of type "%s".', $template, $type));
}

$unlocalizedData = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function map(
DimensionContentCollectionInterface $dimensionContentCollection
): void {
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();
$unlocalizedDimensionAttributes = array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]);
$unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes);

if (!$unlocalizedObject instanceof WorkflowInterface) {
Expand All @@ -35,7 +35,7 @@ public function map(

if ($localizedObject) {
if (!$localizedObject instanceof WorkflowInterface) {
throw new \RuntimeException(sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', WorkflowInterface::class, \get_class($localizedObject)));
throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', WorkflowInterface::class, \get_class($localizedObject)));
}

$this->setWorkflowData($localizedObject, $data);
Expand Down
6 changes: 3 additions & 3 deletions Content/Application/ContentIndexer/ContentIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function deindex(string $resourceKey, $id, array $dimensionAttributes = [
$locale = $dimensionAttributes['locale'] ?? null;
$stage = $dimensionAttributes['stage'] ?? null;

$search = $this->searchManager->createSearch(sprintf('__id:"%s"', $id))
$search = $this->searchManager->createSearch(\sprintf('__id:"%s"', $id))
->indexes($this->getIndexes($resourceKey, $stage));

if ($locale) {
Expand Down Expand Up @@ -119,9 +119,9 @@ private function loadDimensionContent(
*/
private function getIndexes(string $resourceKey, ?string $stage): array
{
return array_filter(
return \array_filter(
$this->searchManager->getIndexNames(),
function ($indexName) use ($resourceKey, $stage) {
function($indexName) use ($resourceKey, $stage) {
if (null === $stage) {
return $resourceKey === $indexName || $resourceKey . '_published' === $indexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function merge(object $targetObject, object $sourceObject): void
$targetObject->setTemplateKey($templateKey);
}

$targetObject->setTemplateData(array_merge(
$targetObject->setTemplateData(\array_merge(
$targetObject->getTemplateData(),
$sourceObject->getTemplateData()
));
Expand Down
4 changes: 2 additions & 2 deletions Content/Application/ContentNormalizer/ContentNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function normalize(object $object): array
$ignoredAttributes = [];

foreach ($this->normalizers as $normalizer) {
$ignoredAttributes = array_merge(
$ignoredAttributes = \array_merge(
$ignoredAttributes,
$normalizer->getIgnoredAttributes($object)
);
Expand All @@ -62,7 +62,7 @@ public function normalize(object $object): array
$normalizedData = $normalizer->enhance($object, $normalizedData);
}

ksort($normalizedData);
\ksort($normalizedData);

return $normalizedData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function enhance(object $object, array $normalizedData): array
return $normalizedData;
}

$normalizedData = array_merge($normalizedData['templateData'], $normalizedData);
$normalizedData = \array_merge($normalizedData['templateData'], $normalizedData);
unset($normalizedData['templateData']);

$normalizedData['template'] = $normalizedData['templateKey'];
Expand Down
2 changes: 1 addition & 1 deletion Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function apply(
}

if (!$localizedDimensionContent instanceof WorkflowInterface) {
throw new \RuntimeException(sprintf('Expected "%s" but "%s" given.', WorkflowInterface::class, \get_class($localizedDimensionContent)));
throw new \RuntimeException(\sprintf('Expected "%s" but "%s" given.', WorkflowInterface::class, \get_class($localizedDimensionContent)));
}

$workflow = $this->workflowRegistry->get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

interface ContentWorkflowInterface
{
const CONTENT_RICH_ENTITY_CONTEXT_KEY = 'contentRichEntity';
const DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY = 'dimensionContentCollection';
const DIMENSION_ATTRIBUTES_CONTEXT_KEY = 'dimensionAttributes';
public const CONTENT_RICH_ENTITY_CONTEXT_KEY = 'contentRichEntity';
public const DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY = 'dimensionContentCollection';
public const DIMENSION_ATTRIBUTES_CONTEXT_KEY = 'dimensionAttributes';

/**
* @param mixed[] $dimensionAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function onRemoveDraft(TransitionEvent $transitionEvent): void
throw new \RuntimeException('Transition context must contain "contentRichEntity".');
}

$draftDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_DRAFT]);
$liveDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_LIVE]);
$draftDimensionAttributes = \array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_DRAFT]);
$liveDimensionAttributes = \array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_LIVE]);

$this->contentCopier->copy(
$contentRichEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function onUnpublish(TransitionEvent $transitionEvent): void
throw new \RuntimeException('Transition context must contain "contentRichEntity".');
}

$liveDimensionAttributes = array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_LIVE]);
$liveDimensionAttributes = \array_merge($dimensionAttributes, ['stage' => DimensionContentInterface::STAGE_LIVE]);

$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $liveDimensionAttributes);
$localizedLiveDimensionContent = $dimensionContentCollection->getDimensionContent($liveDimensionAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function create(
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionAttributes);
$dimensionAttributes = $dimensionContentCollection->getDimensionAttributes();

$orderedContentDimensions = iterator_to_array($dimensionContentCollection);
$orderedContentDimensions = \iterator_to_array($dimensionContentCollection);
$dimensionContents = new ArrayCollection($orderedContentDimensions);

$unlocalizedAttributes = $dimensionAttributes;
Expand Down
4 changes: 2 additions & 2 deletions Content/Domain/Exception/ContentNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class ContentNotFoundException extends \Exception
*/
public function __construct(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes)
{
parent::__construct(sprintf(
parent::__construct(\sprintf(
'Could not load content with id "%s" and attributes: %s',
$contentRichEntity->getId(),
json_encode($dimensionAttributes)
\json_encode($dimensionAttributes)
));
}
}
6 changes: 3 additions & 3 deletions Content/Domain/Model/DimensionContentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public function __construct(
$this->defaultDimensionAttributes = $dimensionContentClass::getDefaultDimensionAttributes();

$this->unlocalizedDimensionContent = $this->dimensionContents->filter(
function (DimensionContentInterface $dimensionContent) {
function(DimensionContentInterface $dimensionContent) {
return null === $dimensionContent->getLocale();
}
)->first() ?: null;

$this->localizedDimensionContent = $this->dimensionContents->filter(
function (DimensionContentInterface $dimensionContent) {
function(DimensionContentInterface $dimensionContent) {
return null !== $dimensionContent->getLocale();
}
)->first() ?: null;
Expand All @@ -89,7 +89,7 @@ public function getDimensionContentClass(): string

public function getDimensionContent(array $dimensionAttributes): ?DimensionContentInterface
{
$dimensionAttributes = array_merge($this->defaultDimensionAttributes, $dimensionAttributes);
$dimensionAttributes = \array_merge($this->defaultDimensionAttributes, $dimensionAttributes);

$criteria = Criteria::create();
foreach ($dimensionAttributes as $key => $value) {
Expand Down
4 changes: 2 additions & 2 deletions Content/Domain/Model/DimensionContentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

interface DimensionContentInterface
{
const STAGE_DRAFT = 'draft';
const STAGE_LIVE = 'live';
public const STAGE_DRAFT = 'draft';
public const STAGE_LIVE = 'live';

public static function getResourceKey(): string;

Expand Down
Loading

0 comments on commit bd6674a

Please sign in to comment.