Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/_lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ jobs:
- name: Run PHP-CS-Fixer
run: composer run lint-composer

lint-php:
name: Lint PHP
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./.github/actions/composer
with:
composer-install: 'false'
- name: Run PHP-CS-Fixer
run: composer run lint-php

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,6 +57,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./.github/actions/composer
with:
composer-install: 'false'
- uses: actions/setup-node@v4
with:
node-version: 22
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"lint": [
"@lint-composer",
"@lint-php",
"@lint-php-cs-fixer",
"@lint-phpstan",
"@lint-prettier"
Expand All @@ -76,6 +77,7 @@
"@lint-php-cs-fixer-fix",
"@lint-prettier-fix"
],
"lint-php": "failed=1; find . -name \"*.php\" -not -path \"./vendor/*\" -not -path \"./var/*\" -exec php -l \"{}\" \\; 2>&1 | grep \"PHP Parse error\" || failed=0; test \"$failed\" -eq \"0\"",
"lint-php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --dry-run",
"lint-php-cs-fixer-fix": "vendor/bin/php-cs-fixer fix",
"lint-phpstan": [
Expand All @@ -92,7 +94,7 @@
"phpunit": "@php vendor/bin/phpunit",
"phpunit-html": [
"rm public/tests -rf",
"@php vendor/bin/phpunit --coverage-html public/tests"
"@php -dextension=pcov.so -dpcov.enabled=1 vendor/bin/phpunit --coverage-html public/tests"
],
"phpunit-report": "@php -dpcov.enabled=1 vendor/bin/phpunit --coverage-html public/tests --coverage-clover reports/coverage.clover.xml --coverage-text --colors=always --testdox"
}
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ parameters:
- identifier: property.internalClass
- identifier: property.internalInterface
- identifier: return.internalClass
- identifier: staticMethod.internal

services:
- # register the class, so we can decorate it, but don't tag it as a rule, so only our decorator is used by PHPStan
Expand Down
9 changes: 7 additions & 2 deletions src/ApiDefinition/EntitySchemaGeneratorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
final class EntitySchemaGeneratorDecorator extends EntitySchemaGenerator
{
private const array CLEANUP_PROPERTY_DEFINITION = [
private const CLEANUP_PROPERTY_DEFINITION = [
'type' => 'boolean',
'flags' => [
// Reading is never allowed, the field is not returned by the API
Expand All @@ -32,7 +32,12 @@ final class EntitySchemaGeneratorDecorator extends EntitySchemaGenerator
],
];

public function __construct(private ApiDefinitionGeneratorInterface $decorated) {}
/**
* @codeCoverageIgnore
*/
public function __construct(
private readonly ApiDefinitionGeneratorInterface $decorated,
) {}

/**
* @codeCoverageIgnore
Expand Down
8 changes: 4 additions & 4 deletions src/DataAbstractionLayer/CleanupRelationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ final class CleanupRelationData
* @param array<non-empty-string, true> $relatedPrimaryKeyFields
*/
public function __construct(
readonly public EntityDefinition $definition,
readonly public array $parentPrimaryKey,
readonly public array $parentPrimaryKeyFields,
readonly public array $relatedPrimaryKeyFields,
public readonly EntityDefinition $definition,
public readonly array $parentPrimaryKey,
public readonly array $parentPrimaryKeyFields,
public readonly array $relatedPrimaryKeyFields,
) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DataAbstractionLayer/ObsoleteRelationsDeleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function getDeletePrimaryKeys(CleanupRelationData $cleanupRelation, Cont
$this->getMainPrimaryKey($cleanupRelation->parentPrimaryKey),
),
);
$criteria->addFilter(new NotFilter(MultiFilter::CONNECTION_AND, $existingIdFilters));
$criteria->addFilter(new NotFilter(MultiFilter::CONNECTION_OR, $existingIdFilters));

return $repository->searchIds($criteria, $context)->getIds();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function filterVersionFields(array $primaryKeys, EntityDefinition $defin
private function getForeignKeyPropertyNameByStorageName(
CompiledFieldCollection $fields,
string $storageName,
) {
): string {
$fk = $fields->getByStorageName($storageName);

assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class PropertyGroupOptionExcludeDefinition extends MappingEntityDefinition
{
final public const string ENTITY_NAME = 'property_group_option_exclude';
final public const ENTITY_NAME = 'property_group_option_exclude';

public function getEntityName(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class PropertyGroupOptionExcludeExtension extends EntityExtension
{
public const string EXTENSION_NAME = 'excludedOptions';
public const EXTENSION_NAME = 'excludedOptions';

public function extendFields(FieldCollection $collection): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Swh\SmartRelationSyncTestPlugin\Entity;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @extends EntityCollection<VersionedChildEntity>
*/
class VersionedChildCollection extends EntityCollection
{
protected function getExpectedClass(): string
{
return VersionedChildEntity::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Swh\SmartRelationSyncTestPlugin\Entity;

use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\VersionField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

class VersionedChildDefinition extends EntityDefinition
{
final public const ENTITY_NAME = 'versioned_child';

public function getCollectionClass(): string
{
return VersionedChildCollection::class;
}

public function getEntityClass(): string
{
return VersionedChildEntity::class;
}

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required(), new ApiAware()),
new VersionField(),
(new ReferenceVersionField(VersionedParentDefinition::class, 'parent_version_id'))
->addFlags(new Required(), new ApiAware()),
(new StringField('name', 'name'))->addFlags(new Required(), new ApiAware()),

(new FkField('parent_id', 'parentId', VersionedParentDefinition::class))
->addFlags(new Required(), new ApiAware()),
(new ManyToOneAssociationField('parent', 'parent_id', VersionedParentDefinition::class))
->addFlags(new ApiAware()),
]);
}

protected function getParentDefinitionClass(): ?string
{
return VersionedParentDefinition::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Swh\SmartRelationSyncTestPlugin\Entity;

use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;

class VersionedChildEntity extends Entity
{
use EntityIdTrait;

protected ?string $name = null;

protected ?VersionedParentEntity $parent = null;

protected ?string $parentId = null;

protected string $parentVersionId;

public function getName(): ?string
{
return $this->name;
}

public function getParent(): ?VersionedParentEntity
{
return $this->parent;
}

public function getParentId(): ?string
{
return $this->parentId;
}

public function getParentVersionId(): string
{
return $this->parentVersionId;
}

public function setName(?string $name): void
{
$this->name = $name;
}

public function setParent(?VersionedParentEntity $parent): void
{
$this->parent = $parent;
}

public function setParentId(string $parentId): void
{
$this->parentId = $parentId;
}

public function setParentVersionId(string $parentVersionId): void
{
$this->parentVersionId = $parentVersionId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Swh\SmartRelationSyncTestPlugin\Entity;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @extends EntityCollection<VersionedParentEntity>
*/
class VersionedParentCollection extends EntityCollection
{
protected function getExpectedClass(): string
{
return VersionedParentEntity::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Swh\SmartRelationSyncTestPlugin\Entity;

use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\VersionField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

class VersionedParentDefinition extends EntityDefinition
{
final public const ENTITY_NAME = 'versioned_parent';

public function getCollectionClass(): string
{
return VersionedParentCollection::class;
}

public function getEntityClass(): string
{
return VersionedParentEntity::class;
}

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required(), new ApiAware()),
(new VersionField())->addFlags(new ApiAware()),
(new ReferenceVersionField(self::class, 'parent_version_id'))->addFlags(new Required(), new ApiAware()),

(new StringField('name', 'name'))
->addFlags(new Required(), new ApiAware()),

(new OneToManyAssociationField('children', VersionedChildDefinition::class, 'parent_id'))
->addFlags(new CascadeDelete(), new ApiAware()),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Swh\SmartRelationSyncTestPlugin\Entity;

use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;

class VersionedParentEntity extends Entity
{
use EntityIdTrait;

protected ?VersionedChildCollection $children = null;

protected string $name;

protected string $parentVersionId;

public function getChildren(): ?VersionedChildCollection
{
return $this->children;
}

public function getName(): string
{
return $this->name;
}

public function getParentVersionId(): string
{
return $this->parentVersionId;
}

public function setChildren(VersionedChildCollection $children): void
{
$this->children = $children;
}

public function setName(string $name): void
{
$this->name = $name;
}

public function setParentVersionId(string $parentVersionId): void
{
$this->parentVersionId = $parentVersionId;
}
}
Loading