Skip to content

Commit

Permalink
Fix code style (#228)
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Fehr <mario.fehr@massiveart.com>
  • Loading branch information
alexander-schranz and mario-fehr committed Oct 3, 2022
1 parent dd5ae56 commit 16de307
Show file tree
Hide file tree
Showing 79 changed files with 376 additions and 385 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -28,7 +28,7 @@ package-lock.json
Tests/Application/var
Tests/Application/public/build
Tests/Application/.env.local
Tests/Application/.env.test.local
Tests/Application/.env.*.local
Tests/reports/

# IDEs
Expand Down
31 changes: 14 additions & 17 deletions .php_cs.dist → .php-cs-fixer.dist.php
@@ -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;
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
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
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
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
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
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
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
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector;

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;

class ContentMetadataInspector implements ContentMetadataInspectorInterface
{
Expand All @@ -30,6 +31,7 @@ public function __construct(EntityManagerInterface $entityManager)
public function getDimensionContentClass(string $contentRichEntityClass): string
{
$classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass);
/** @var array{targetEntity: class-string<DimensionContentInterface>} $associationMapping */
$associationMapping = $classMetadata->getAssociationMapping('dimensionContents');

return $associationMapping['targetEntity'];
Expand All @@ -38,6 +40,7 @@ public function getDimensionContentClass(string $contentRichEntityClass): string
public function getDimensionContentPropertyName(string $contentRichEntityClass): string
{
$classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass);
/** @var array{mappedBy: string} $associationMapping */
$associationMapping = $classMetadata->getAssociationMapping('dimensionContents');

return $associationMapping['mappedBy'];
Expand Down
4 changes: 2 additions & 2 deletions Content/Application/ContentNormalizer/ContentNormalizer.php
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
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
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
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
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
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
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
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
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
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

0 comments on commit 16de307

Please sign in to comment.