Skip to content

Commit b8ef5e7

Browse files
authored
Update php to 8 (#44)
1 parent 31c5c9b commit b8ef5e7

File tree

8 files changed

+30
-34
lines changed

8 files changed

+30
-34
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php-versions: ['7.4']
17+
php-versions: ['7.4', '8.0']
1818

1919
steps:
2020
- uses: actions/checkout@v2
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/cache@v2
3636
with:
3737
path: vendor
38-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
38+
key: ${{ runner.os }}-php-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
3939
restore-keys: |
4040
${{ runner.os }}-php-
4141

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ test: ## Run tests
3030
coverage: ## Run tests with coverage
3131
$(php_container_bin) composer run-script coverage
3232

33-
entites: ## Build entities from yaml file with description
34-
$(php_container_bin) composer run-script entites
33+
entities: ## Build entities from yaml file with description
34+
$(php_container_bin) composer run-script entities

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"keywords": ["php", "fias", "elasticsearch"],
66
"license": "MIT",
77
"require": {
8-
"php": ">=7.4.0",
9-
"liquetsoft/fias-component": "^7.0",
8+
"php": ">=7.4",
9+
"liquetsoft/fias-component": "^8.0",
1010
"elasticsearch/elasticsearch": "^7.6",
1111
"psr/log": "^1.1",
1212
"ext-json": "*"
1313
},
1414
"require-dev": {
1515
"phpunit/phpunit": "^9.0",
16-
"fzaninotto/faker": "^1.7",
16+
"fakerphp/faker": "^1.7",
1717
"friendsofphp/php-cs-fixer": "^2.11",
1818
"sebastian/phpcpd": "^6.0",
1919
"vimeo/psalm": "^4.0",
@@ -35,7 +35,7 @@
3535
"coverage": "vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-html=tests/coverage",
3636
"fixer": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v",
3737
"linter": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation && vendor/bin/phpcpd ./ --exclude vendor --exclude tests --exclude src/Entity --exclude src/Serializer && vendor/bin/psalm --show-info=true",
38-
"entites": "php -f generator/generate_entities.php && vendor/bin/php-cs-fixer fix --config=.php_cs.dist -q"
38+
"entities": "php -f generator/generate_entities.php && vendor/bin/php-cs-fixer fix --config=.php_cs.dist -q"
3939
},
4040
"repositories": [
4141
{

docker/php/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.4-cli-alpine
1+
FROM php:8-cli-alpine
22

33

44
RUN set -xe && apk update && apk add --no-cache \
@@ -24,7 +24,7 @@ RUN docker-php-ext-install zip soap \
2424
&& echo 'xdebug.mode=coverage' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
2525

2626

27-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.0.1 \
27+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.0.11 \
2828
&& mkdir -p /.composer && chmod -Rf 777 /.composer
2929

3030

generator/MapperTestGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ private function decorateHasPropertyTest(Method $method, EntityDescriptor $descr
211211
{
212212
$entityName = $this->getTestedObjectName($descriptor);
213213

214-
$propertyName = $this->unifyColumnName(reset($descriptor->getFields())->getName());
214+
$fields = $descriptor->getFields();
215+
$firstField = reset($fields);
216+
$propertyName = $this->unifyColumnName($firstField->getName());
215217

216218
$method->addBody("\$mapper = new $entityName();");
217219
$method->addBody('');

generator/SerializerGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ protected function decorateClass(ClassType $class): void
8888
$denormalizeBody .= "\$entity = \$context[AbstractNormalizer::OBJECT_TO_POPULATE] ?? new \$type();\n\n";
8989
foreach ($descriptors as $descriptor) {
9090
$className = $this->unifyClassName($descriptor->getName());
91-
$supports[] = $className;
91+
$supports = [
92+
$className,
93+
];
9294
if ($count === 0) {
9395
$denormalizeBody .= "if (\$entity instanceof {$className}) {\n";
9496
$supportsBody .= "is_subclass_of(\$type, {$className}::class)";

generator/generate_entities.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,56 @@
11
<?php
22

33
use Liquetsoft\Fias\Component\EntityRegistry\PhpArrayFileRegistry;
4-
use Liquetsoft\Fias\Component\Helper\FileSystemHelper;
54
use Liquetsoft\Fias\Elastic\Generator\MapperGenerator;
65
use Liquetsoft\Fias\Elastic\Generator\MapperTestGenerator;
76
use Liquetsoft\Fias\Elastic\Generator\ModelGenerator;
87
use Liquetsoft\Fias\Elastic\Generator\ModelTestGenerator;
98
use Liquetsoft\Fias\Elastic\Generator\NormalizerGenerator;
109
use Liquetsoft\Fias\Elastic\Generator\SerializerGenerator;
10+
use Marvin255\FileSystemHelper\FileSystemFactory;
1111

1212
$root = dirname(__DIR__);
1313

14-
require_once $root . '/vendor/autoload.php';
14+
require_once dirname(__DIR__) . '/vendor/autoload.php';
1515

16+
$fs = FileSystemFactory::create();
1617
$registry = new PhpArrayFileRegistry();
1718

1819
$dir = $root . '/src/Entity';
19-
if (is_dir($dir)) {
20-
FileSystemHelper::remove(new SplFileInfo($dir));
21-
}
22-
mkdir($dir, 0777, true);
20+
$fs->mkdirIfNotExist($dir);
21+
$fs->emptyDir($dir);
2322
$dirObject = new SplFileInfo($dir);
2423
$namespace = 'Liquetsoft\\Fias\\Elastic\\Entity';
2524
$generator = new ModelGenerator($registry);
2625
$generator->run($dirObject, $namespace);
2726

2827
$dir = $root . '/tests/Entity';
29-
if (is_dir($dir)) {
30-
FileSystemHelper::remove(new SplFileInfo($dir));
31-
}
32-
mkdir($dir, 0777, true);
28+
$fs->mkdirIfNotExist($dir);
29+
$fs->emptyDir($dir);
3330
$dirObject = new SplFileInfo($dir);
3431
$namespace = 'Liquetsoft\\Fias\\Elastic\\Tests\\Entity';
3532
$generator = new ModelTestGenerator($registry);
3633
$generator->run($dirObject, $namespace);
3734

3835
$dir = $root . '/src/IndexMapper';
39-
if (is_dir($dir)) {
40-
FileSystemHelper::remove(new SplFileInfo($dir));
41-
}
42-
mkdir($dir, 0777, true);
36+
$fs->mkdirIfNotExist($dir);
37+
$fs->emptyDir($dir);
4338
$dirObject = new SplFileInfo($dir);
4439
$namespace = 'Liquetsoft\\Fias\\Elastic\\IndexMapper';
4540
$generator = new MapperGenerator($registry);
4641
$generator->run($dirObject, $namespace);
4742

4843
$dir = $root . '/tests/IndexMapper';
49-
if (is_dir($dir)) {
50-
FileSystemHelper::remove(new SplFileInfo($dir));
51-
}
52-
mkdir($dir, 0777, true);
44+
$fs->mkdirIfNotExist($dir);
45+
$fs->emptyDir($dir);
5346
$dirObject = new SplFileInfo($dir);
5447
$namespace = 'Liquetsoft\\Fias\\Elastic\\Tests\\IndexMapper';
5548
$generator = new MapperTestGenerator($registry);
5649
$generator->run($dirObject, $namespace);
5750

5851
$dir = new SplFileInfo($root . '/src/Serializer');
59-
if (is_dir($dir)) {
60-
FileSystemHelper::remove(new SplFileInfo($dir));
61-
}
62-
mkdir($dir, 0777, true);
52+
$fs->mkdirIfNotExist($dir);
53+
$fs->emptyDir($dir);
6354
$namespace = 'Liquetsoft\\Fias\\Elastic\\Serializer';
6455
$generator = new SerializerGenerator($registry);
6556
$generator->run($dir, $namespace);

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
>
99
<projectFiles>
1010
<directory name="./src" />
11+
<directory name="./generator" />
1112
<ignoreFiles>
1213
</ignoreFiles>
1314
</projectFiles>

0 commit comments

Comments
 (0)