Skip to content

Commit a1488b4

Browse files
committed
Expanded the rules to cover additional use cases
1 parent 5cea38a commit a1488b4

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ composer phpstan -- --generate-baseline
6969
### Deptrac
7070

7171
This repository uses Deptrac to test the code samples. To run the tests locally execute the commands below:
72+
7273
```bash
7374
composer update
7475
composer deptrac

code_samples/catalog/custom_attribute_type/src/Attribute/Percent/Storage/PercentStorageConverter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
namespace App\Attribute\Percent\Storage;
66

77
use Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageConverterInterface;
8-
use Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageSchema;
98
use Webmozart\Assert\Assert;
109

1110
final class PercentStorageConverter implements StorageConverterInterface
1211
{
1312
public function fromPersistence(array $data)
1413
{
15-
$value = $data[StorageSchema::COLUMN_VALUE];
14+
$value = $data['value'];
1615
Assert::nullOrNumeric($value);
1716

1817
return $value;
@@ -23,7 +22,7 @@ public function toPersistence($value): array
2322
Assert::nullOrNumeric($value);
2423

2524
return [
26-
StorageSchema::COLUMN_VALUE => $value,
25+
'value' => $value,
2726
];
2827
}
2928
}

code_samples/catalog/custom_attribute_type/src/Attribute/Percent/Storage/PercentStorageDefinition.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@
1010

1111
use Doctrine\DBAL\Types\Types;
1212
use Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface;
13-
use Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageSchema;
1413

1514
final class PercentStorageDefinition implements StorageDefinitionInterface
1615
{
1716
public function getColumns(): array
1817
{
1918
return [
20-
StorageSchema::COLUMN_VALUE => Types::FLOAT,
19+
'value' => Types::FLOAT,
2120
];
2221
}
2322

2423
public function getTableName(): string
2524
{
26-
return StorageSchema::TABLE_NAME;
25+
return 'app_product_specification_attribute_percent';
2726
}
2827
}

deptrac.baseline.yaml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
11
deptrac:
22
skip_violations:
3-
Acme\ExampleBundle\DependencyInjection\AcmeExampleExtension:
4-
- Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor
5-
- Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface
6-
Acme\ExampleBundle\DependencyInjection\Configuration:
7-
- Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration
83
App\AI\REST\Input\Parser\TranscribeAudio:
9-
- Ibexa\ConnectorAi\REST\Input\Parser\Action
104
- Ibexa\Rest\Input\BaseParser
11-
App\AI\REST\Output\Resolver\AudioTextResolver:
12-
- Ibexa\ConnectorAi\REST\Output\ResolverInterface
13-
App\AI\REST\Value\AudioText:
14-
- Ibexa\ConnectorAi\REST\Value\RestActionResponse
15-
App\Attribute\Percent\Form\PercentValueFormMapper:
16-
- Ibexa\Bundle\ProductCatalog\Validator\Constraints\AttributeValue
17-
App\Attribute\Percent\PercentOptionsFormMapper:
18-
- Ibexa\Bundle\ProductCatalog\Validator\Constraints\AttributeDefinitionOptions
19-
App\Attribute\Percent\Storage\PercentStorageConverter:
20-
- Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageSchema
21-
App\Attribute\Percent\Storage\PercentStorageDefinition:
22-
- Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageSchema
23-
App\AutomatedTranslation\AiClient:
24-
- Ibexa\AutomatedTranslation\Exception\ClientNotConfiguredException
255
App\AutomatedTranslation\ImageFieldEncoder:
266
- Ibexa\Core\FieldType\Image\Value
277
App\Block\Listener\MyBlockListener:
@@ -73,7 +53,7 @@ deptrac:
7353
App\Controller\CustomCheckoutController:
7454
- Ibexa\Bundle\Core\Controller
7555
App\Controller\CustomController:
76-
- Ibexa\Bundle\Core\Controller
56+
- Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute
7757
App\Controller\CustomFilterController:
7858
- Ibexa\Bundle\Core\Controller
7959
- Ibexa\Core\MVC\Symfony\View\ContentView
@@ -158,8 +138,12 @@ deptrac:
158138
- Ibexa\Migration\ValueObject\Step\StepInterface
159139
App\Migrations\Step\ReplaceNameStepNormalizer:
160140
- Ibexa\Migration\ValueObject\Step\StepInterface
141+
App\Notification\ListRenderer:
142+
- Ibexa\Core\Notification\Renderer\NotificationRenderer
143+
- Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface
161144
App\Notification\MyRenderer:
162145
- Ibexa\Core\Notification\Renderer\NotificationRenderer
146+
- Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface
163147
App\OAuth\GoogleResourceOwnerMapper:
164148
- Ibexa\OAuth2Client\ResourceOwner\ResourceOwnerToExistingOrNewUserMapper
165149
App\QueryType\LatestContentQueryType:

deptrac.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,40 @@ deptrac:
1313
collectors:
1414
- type: classLike
1515
value: .*Ibexa\\Contracts\\.*
16-
- name: IbexaNotContracts
16+
- name: IbexaSiteAccessConfiguration
17+
collectors:
18+
- type: classLike
19+
value: .*Ibexa\\Bundle\\Core\\DependencyInjection\\Configuration\\SiteAccessAware\\.*
20+
- name: IbexaInternal
21+
collectors:
22+
- type: tagValueRegex
23+
tag: '@internal'
24+
- name: IbexaRest
25+
collectors:
26+
- type: classLike
27+
value: .*Ibexa\\.*\\Rest\\.*
28+
- name: IbexaConstraints
29+
collectors:
30+
- type: classLike
31+
value: .*Ibexa\\.*\\Constraints\\.*
32+
- name: IbexaNotAllowed
1733
collectors:
1834
- type: bool
1935
must:
2036
- type: classLike
2137
value: .*Ibexa\\.*
2238
must_not:
23-
- type: classLike
24-
value: .*Ibexa\\Contracts.*
39+
- type: layer
40+
value: IbexaContracts
41+
- type: layer
42+
value: IbexaSiteAccessConfiguration
43+
- type: layer
44+
value: IbexaRest
45+
- type: layer
46+
value: IbexaConstraints
2547
ruleset:
2648
CodeSamples:
2749
- IbexaContracts
50+
- IbexaSiteAccessConfiguration
51+
- IbexaRest
52+
- IbexaConstraints

docs/pim/create_custom_attribute_type.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ Register the validator as a service and tag it with `ibexa.product_catalog.attri
120120

121121
To ensure that values of the new attributes are stored correctly, you need to provide a storage converter and storage definition services.
122122

123+
### Database schema design
124+
125+
The values are going to be stored within a table named `app_product_specification_attribute_percent`, in a column named `value`.
126+
127+
=== "MySQL"
128+
129+
``` sql
130+
CREATE TABLE app_product_specification_attribute_percent (id INT NOT NULL, value DOUBLE PRECISION DEFAULT NULL, INDEX app_product_specification_attribute_percent_value_idx (value), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB;
131+
ALTER TABLE app_product_specification_attribute_percent ADD CONSTRAINT app_product_specification_attribute_percent_fk FOREIGN KEY (id) REFERENCES ibexa_product_specification_attribute (id) ON UPDATE CASCADE ON DELETE CASCADE;
132+
```
133+
134+
=== "PostgreSQL"
135+
136+
``` sql
137+
CREATE TABLE app_product_specification_attribute_percent (id INT NOT NULL, value DOUBLE PRECISION DEFAULT NULL, PRIMARY KEY(id));
138+
CREATE INDEX app_product_specification_attribute_percent_value_idx ON app_product_specification_attribute_percent (value);
139+
ALTER TABLE app_product_specification_attribute_percent ADD CONSTRAINT app_product_specification_attribute_percent_fk FOREIGN KEY (id) REFERENCES ibexa_product_specification_attribute (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
140+
```
141+
123142
### Storage converter
124143

125144
Start by creating a `PercentStorageConverter` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageConverterInterface`.

0 commit comments

Comments
 (0)