Skip to content

Commit e2c20c4

Browse files
authored
Merge pull request #54 from picamator/development
Release 5.4.6
2 parents b042528 + a21d0de commit e2c20c4

32 files changed

+272
-162
lines changed

.aiignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# cache and debug
55
var/cache/
66
var/xdebug-profile/
7+
8+
# secret
9+
.env

.github/pull_request_template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Type of Change
1414
Please delete options that are not relevant:
1515

1616
- [ ] Bug fix (non-breaking change which fixes an issue)
17+
- [ ] Improvements (non-breaking changes such as refactoring, performance optimization, etc.)
1718
- [ ] New feature (non-breaking change which adds functionality)
18-
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
19+
- [ ] Breaking change (bug fix, new feature, dependency upgrade, etc.)
1920
- [ ] Documentation update
2021
- [ ] Other (please specify):
2122

AGENTS.md

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ Directory Structure
4343

4444
### Examples
4545

46-
- `examples`: samples how to use `DefinitionGeneratorFacade` and `TransferGeneratorFacade`
46+
- `examples`: samples on how to use `DefinitionGeneratorFacade` and `TransferGeneratorFacade`
4747

4848
### Source
4949

5050
- `src`: code source
5151
- `src/Command`: Symfony console commands to generate definition and transfer object files
5252
- `src/DefinitionGenerator`: definition generator module
53-
- `src/Dependency`: wrapper over 3-part dependencies
53+
- `src/Dependency`: wrapper over third-party dependencies
5454
- `src/Generated`: directory where generated transfer objects are saved
5555
* should not contain any custom-written code
56-
* each transfer object generator run will overwrite all the files in the directory
56+
* each transfer object generator run overwrites all the files in the directory
5757
* can be used across modules
58-
- `src/Generated/_tmp`: temporary directory includes newly generated transfer objects before they are finally moved to the `src/Generated`
59-
* in case of an unexpected error, the directory might not be deleted
58+
- `src/Generated/_tmp`: temporary directory including newly generated transfer objects before they are finally moved to the `src/Generated`
59+
* in case of an unexpected error, the directory might not be deleted.
6060
- `src/Shared`: contains code shared across modules
6161
* can be used across modules
6262
- `src/Transfer`: transfer object module
@@ -100,20 +100,20 @@ Code Style
100100

101101
### Tests
102102

103-
- tests classes should be a `final`
103+
- test classes should be `final`
104104
- tests should have at least one test group
105105

106106
Module Structure
107107
----------------
108108

109109
#### Facade
110110

111-
- each module should have a facade class with an interface
112-
- the facade class and interface name should include the module name with `Facade` suffix
113-
- the facade is used for communication between modules
114-
- the facade used factories
115-
- the facade should not include any business logic
116-
- the facade `public` methods should have specification doc-block
111+
- each module should have a facade class with an interface.
112+
- the facade class and interface name should include the module name with `Facade` suffix.
113+
- the facade is used for communication between modules.
114+
- the facade uses factories.
115+
- the facade should not include any business logic.
116+
- the facade `public` methods should have a specification doc-block.
117117

118118
### Factory
119119

@@ -129,34 +129,42 @@ Module Structure
129129
Unit and Integration Tests
130130
--------------------------
131131

132-
- tests should follow a similar structure to the existing ones
133-
- separate test implementation by comment sections: "Arrange", "Act", "Assert" (optionally with "Expect")
134-
- use `setUp` method to initialize the tested object's stubs and mocks
135-
- use `PHPUnit` attributes
136-
- use [PHP generator](https://www.php.net/manual/en/class.generator.php) for the data providers
132+
- tests should follow a similar structure to the existing ones.
133+
- separate test implementation by comment sections: "Arrange", "Act", "Assert" (optionally with "Expect").
134+
- use `setUp` method to initialize the tested object's stubs and mocks.
135+
- use `PHPUnit` attributes.
136+
- use [PHP generator](https://www.php.net/manual/en/class.generator.php) for the data providers.
137+
138+
How To Install Project
139+
----------------------
140+
141+
The project is installed by running the following command:
142+
```console
143+
docker/sdk install
144+
```
137145

138146
How To Build/Start/Stop Docker Environment
139147
-------------------------------------------
140148

141-
Docker Environment can be built by running the following command:
149+
Docker Environment is built by running the following command:
142150
```console
143151
docker/sdk build
144152
```
145153

146-
Docker Environment can be started by running the following command:
154+
Docker Environment is started by running the following command:
147155
```console
148156
docker/sdk start
149157
```
150158

151-
Docker Environment can be stopped by running the following command:
159+
Docker Environment is stopped by running the following command:
152160
```console
153161
docker/sdk stop
154162
```
155163

156164
How to Run PHP Script
157165
---------------------
158166

159-
The PHP script can be run by command:
167+
The PHP script runs by command:
160168
```console
161169
docker/sdk cli [path-to-script]
162170
```
@@ -169,7 +177,7 @@ docker/sdk cli ./examples/try-transfer-generator.php
169177
How to Generate Internal Transfer Objects
170178
-----------------------------------------
171179

172-
The all project transfer objects (generator's, examples, tests) can be generated with the following command:
180+
All project transfer objects (generator's, examples, tests) can be generated with the following command:
173181
```console
174182
docker/sdk to-generate-bulk
175183
```
@@ -182,29 +190,29 @@ docker/sdk to-generate
182190
How to Generate Transfer Objects By Configuration File
183191
------------------------------------------------------
184192

185-
Transfer Objects can be generated by configuration file path, relative from the project's root, by running the following command:
193+
Transfer objects can be generated by a configuration file path, relative from the project's root, by running the following command:
186194
```console
187195
docker/sdk to-generate [path-to-configuration-file]
188196
```
189197

190-
How To Run PHPUnit Tests
198+
How to Run PHPUnit Tests
191199
------------------------
192200

193-
### All Tests
201+
### How to Run All Tests
194202

195203
All tests can be run with the following command:
196204
```console
197205
docker/sdk phpunit
198206
```
199207

200-
### Specific Group
208+
### How to Run Test Group
201209

202210
A test group can be run with the following command:
203211
```console
204212
docker/sdk phpunit-group <group>
205213
```
206214

207-
### Specific Test Case
215+
### How to Run Test Case
208216

209217
A test case can be run with the following command:
210218
```console
@@ -217,26 +225,54 @@ can be run with the following command:
217225
docker/sdk phpunit 'Picamator\\Tests\\Unit\\TransferObject\\Command\\Helper\\InputNormalizerTest'
218226
```
219227

220-
How To Run PHPStan
228+
How to Run PHPStan
221229
------------------
222230

223-
PHPStan can be run with the following command:
231+
For all project's files, PHPStan can be run with the following command:
224232
```console
225233
docker/sdk phpstan
226234
```
227235

228-
How To Run PHP CodeSniffer
236+
For the specific file:
237+
```console
238+
docker/sdk phpstan <file-path>
239+
```
240+
241+
How to Run PHP CodeSniffer
229242
--------------------------
230243

231-
PHP CodeSniffer can be run with the following command:
244+
For all project's files, PHP CodeSniffer can be run with the following command:
232245
```console
233246
docker/sdk phpcs
234247
```
235248

236-
How To Run Composer
249+
For the specific file:
250+
```console
251+
docker/sdk phpcs <file-path>
252+
```
253+
254+
How to Run PHP Code Beautifier and Fixer
255+
----------------------------------------
256+
257+
For all project's files, PHP Code Beautifier and Fixer can be run with the following command:
258+
```console
259+
docker/sdk phpcbf
260+
```
261+
262+
For the specific file:
263+
```console
264+
docker/sdk phpcbf <file-path>
265+
```
266+
267+
How to Run Composer
237268
-------------------
238269

239-
PHPStan can be run with the following command:
270+
Composer can be run with the following command:
240271
```console
241272
docker/sdk composer
242273
```
274+
275+
The command supports multiple arguments, for example:
276+
```console
277+
docker/sdk composer install
278+
```

docker/sdk

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function wrap_in_yellow() {
1212

1313
# function to print a command/option with its description
1414
function print_command() {
15-
printf " %-35s %s\n" "$(wrap_in_yellow "$1")" "$2"
15+
printf " %-40s %s\n" "$(wrap_in_yellow "$1")" "$2"
1616
}
1717

1818
# function to print an example with its description
@@ -30,7 +30,7 @@ function show_usage() {
3030
echo
3131
echo "Options:"
3232
print_command "-x" "Enable Xdebug (debug, coverage)"
33-
print_command "-p" "Enable Xdebug (profiler)"
33+
print_command "-p" "Enable Xdebug (profile)"
3434
echo
3535
echo "Commands:"
3636
print_command "install" "Install development environment"
@@ -39,20 +39,20 @@ function show_usage() {
3939
print_command "stop" "Stop Docker containers"
4040
print_command "cli [script]" "Open container shell or execute PHP script"
4141
print_command "composer <cmd>" "Run composer command"
42-
print_command "phpstan" "Run PHPStan"
42+
print_command "phpstan [file]" "Run PHPStan for all project's files or for specified one"
4343
print_command "phpunit [filter]" "Run PHPUnit tests"
44-
print_command "phpunit-group <g>" "Run PHPUnit tests by group"
45-
print_command "phpcs" "Run PHP CodeSniffer"
46-
print_command "phpcbf" "Run PHP Code Beautifier and Fixer"
44+
print_command "phpunit-group [group]" "Run PHPUnit tests by group"
45+
print_command "phpcs [file]" "Run PHP CodeSniffer for all project's files or for specified one"
46+
print_command "phpcbf [file]" "Run PHP Code Beautifier and Fixer for all project's files or for specified one"
4747
print_command "hook-install" "Install CaptainHook"
48-
print_command "hook <cmd>" "Run CaptainHook command"
49-
print_command "to-generate [c]" "Generate transfer objects"
50-
print_command "to-generate-bulk [b]" "Generate bulk transfer objects"
51-
print_command "df-generate" "Generate definitions"
48+
print_command "hook [cmd]" "Run CaptainHook command"
49+
print_command "to-generate [config]" "Generate Transfer Objects from YML definitions"
50+
print_command "to-generate-bulk [bulk]" "Generate Transfer Objects in bulk from a config list"
51+
print_command "df-generate" "Generate definition files from JSON blueprints"
5252
echo
5353
echo "Examples:"
5454
print_example "$0 -x start" "Start containers (Xdebug: debug, coverage)"
55-
print_example "$0 -p start" "Start containers (Xdebug: profiler)"
55+
print_example "$0 -p start" "Start containers (Xdebug: profile)"
5656
print_example "$0 composer install" "Run composer install inside container"
5757
}
5858

@@ -91,7 +91,7 @@ case $1 in
9191
if [ "$XDEBUG_MODE" == "" ]; then
9292
docker compose up -d --remove-orphans
9393
else
94-
XDEBUG_MODE={$XDEBUG_MODE} docker compose up -d --remove-orphans
94+
XDEBUG_MODE=${XDEBUG_MODE} docker compose up -d --remove-orphans
9595
fi
9696
;;
9797
stop)
@@ -108,7 +108,7 @@ case $1 in
108108
$DOCKER_EXEC composer "${@:2}"
109109
;;
110110
phpstan)
111-
$DOCKER_EXEC composer phpstan
111+
$DOCKER_EXEC composer phpstan "${@:2}"
112112
;;
113113
phpunit)
114114
if [ -n "$2" ]; then
@@ -118,13 +118,13 @@ case $1 in
118118
fi
119119
;;
120120
phpunit-group)
121-
$DOCKER_EXEC composer phpunit-group "$2"
121+
$DOCKER_EXEC composer phpunit-group "${@:2}"
122122
;;
123123
phpcs)
124-
$DOCKER_EXEC composer phpcs
124+
$DOCKER_EXEC composer phpcs "${@:2}"
125125
;;
126126
phpcbf)
127-
$DOCKER_EXEC composer phpcbf
127+
$DOCKER_EXEC composer phpcbf "${@:2}"
128128
;;
129129
hook-install)
130130
$DOCKER_EXEC composer captainhook install --only-enabled --run-mode=docker --run-exec="docker exec -i $DOCKER_CONTAINER_NAME"

src/Transfer/AbstractTransfer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
*/
1414
abstract class AbstractTransfer implements TransferInterface
1515
{
16-
use AttributeTrait;
16+
use AttributeTrait {
17+
getInitiatorAttribute as private;
18+
getTransformerAttribute as private;
19+
}
1720

1821
/**
1922
* @var int<0, max>
@@ -115,6 +118,10 @@ final public function toArray(): array
115118
$index = $metaData[$propertyName];
116119
$value = $this->_data[$index];
117120

121+
if ($value === null) {
122+
continue;
123+
}
124+
118125
$data[$propertyName] = $this->getTransformerAttribute($constantName)->toArray($value);
119126
unset($metaData[$propertyName]);
120127
}

src/Transfer/Attribute/AttributeTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait AttributeTrait
1717
*/
1818
private static array $_attributeCache = [];
1919

20-
final protected function getInitiatorAttribute(string $constantName): InitiatorAttributeInterface
20+
protected function getInitiatorAttribute(string $constantName): InitiatorAttributeInterface
2121
{
2222
/** @var \ReflectionAttribute<InitiatorAttributeInterface> $reflectionAttribute */
2323
$reflectionAttribute = $this->getConstantReflection(
@@ -34,7 +34,7 @@ final protected function getInitiatorAttribute(string $constantName): InitiatorA
3434
/**
3535
* @throws \Picamator\TransferObject\Transfer\Exception\AttributeTransferException
3636
*/
37-
final protected function getTransformerAttribute(string $constantName): TransformerAttributeInterface
37+
protected function getTransformerAttribute(string $constantName): TransformerAttributeInterface
3838
{
3939
/** @var \ReflectionAttribute<TransformerAttributeInterface> $reflectionAttribute */
4040
$reflectionAttribute = $this->getConstantReflection(

src/Transfer/Attribute/Transformer/DateTimeTransformerAttribute.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function fromArray(mixed $data): DateTimeInterface
4545
}
4646

4747
/**
48-
* @param DateTimeInterface|null $data
48+
* @param DateTimeInterface $data
4949
*/
50-
public function toArray(mixed $data): ?string
50+
public function toArray(mixed $data): string
5151
{
52-
return $data?->format(self::DATE_TIME_FORMAT);
52+
return $data->format(self::DATE_TIME_FORMAT);
5353
}
5454
}

src/Transfer/Attribute/Transformer/EnumTransformerAttribute.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public function fromArray(mixed $data): ?BackedEnum
3535
}
3636

3737
/**
38-
* @param BackedEnum|null $data
38+
* @param BackedEnum $data
3939
*/
40-
public function toArray(mixed $data): string|int|null
40+
public function toArray(mixed $data): string|int
4141
{
42-
return $data?->value;
42+
return $data->value;
4343
}
4444

4545
/**

src/Transfer/Attribute/Transformer/NumberTransformerAttribute.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function fromArray(mixed $data): Number
4040
}
4141

4242
/**
43-
* @param \BcMath\Number|null $data
43+
* @param \BcMath\Number $data
4444
*/
45-
public function toArray(mixed $data): ?string
45+
public function toArray(mixed $data): string
4646
{
47-
return $data?->__toString();
47+
return $data->__toString();
4848
}
4949
}

0 commit comments

Comments
 (0)