Skip to content

Commit

Permalink
Update php to 8 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin255 authored Feb 26, 2021
1 parent 31c5c9b commit b8ef5e7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php-versions: ['7.4']
php-versions: ['7.4', '8.0']

steps:
- uses: actions/checkout@v2
Expand All @@ -35,7 +35,7 @@ jobs:
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ test: ## Run tests
coverage: ## Run tests with coverage
$(php_container_bin) composer run-script coverage

entites: ## Build entities from yaml file with description
$(php_container_bin) composer run-script entites
entities: ## Build entities from yaml file with description
$(php_container_bin) composer run-script entities
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"keywords": ["php", "fias", "elasticsearch"],
"license": "MIT",
"require": {
"php": ">=7.4.0",
"liquetsoft/fias-component": "^7.0",
"php": ">=7.4",
"liquetsoft/fias-component": "^8.0",
"elasticsearch/elasticsearch": "^7.6",
"psr/log": "^1.1",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"fzaninotto/faker": "^1.7",
"fakerphp/faker": "^1.7",
"friendsofphp/php-cs-fixer": "^2.11",
"sebastian/phpcpd": "^6.0",
"vimeo/psalm": "^4.0",
Expand All @@ -35,7 +35,7 @@
"coverage": "vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-html=tests/coverage",
"fixer": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v",
"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",
"entites": "php -f generator/generate_entities.php && vendor/bin/php-cs-fixer fix --config=.php_cs.dist -q"
"entities": "php -f generator/generate_entities.php && vendor/bin/php-cs-fixer fix --config=.php_cs.dist -q"
},
"repositories": [
{
Expand Down
4 changes: 2 additions & 2 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.4-cli-alpine
FROM php:8-cli-alpine


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


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


Expand Down
4 changes: 3 additions & 1 deletion generator/MapperTestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ private function decorateHasPropertyTest(Method $method, EntityDescriptor $descr
{
$entityName = $this->getTestedObjectName($descriptor);

$propertyName = $this->unifyColumnName(reset($descriptor->getFields())->getName());
$fields = $descriptor->getFields();
$firstField = reset($fields);
$propertyName = $this->unifyColumnName($firstField->getName());

$method->addBody("\$mapper = new $entityName();");
$method->addBody('');
Expand Down
4 changes: 3 additions & 1 deletion generator/SerializerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ protected function decorateClass(ClassType $class): void
$denormalizeBody .= "\$entity = \$context[AbstractNormalizer::OBJECT_TO_POPULATE] ?? new \$type();\n\n";
foreach ($descriptors as $descriptor) {
$className = $this->unifyClassName($descriptor->getName());
$supports[] = $className;
$supports = [
$className,
];
if ($count === 0) {
$denormalizeBody .= "if (\$entity instanceof {$className}) {\n";
$supportsBody .= "is_subclass_of(\$type, {$className}::class)";
Expand Down
35 changes: 13 additions & 22 deletions generator/generate_entities.php
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
<?php

use Liquetsoft\Fias\Component\EntityRegistry\PhpArrayFileRegistry;
use Liquetsoft\Fias\Component\Helper\FileSystemHelper;
use Liquetsoft\Fias\Elastic\Generator\MapperGenerator;
use Liquetsoft\Fias\Elastic\Generator\MapperTestGenerator;
use Liquetsoft\Fias\Elastic\Generator\ModelGenerator;
use Liquetsoft\Fias\Elastic\Generator\ModelTestGenerator;
use Liquetsoft\Fias\Elastic\Generator\NormalizerGenerator;
use Liquetsoft\Fias\Elastic\Generator\SerializerGenerator;
use Marvin255\FileSystemHelper\FileSystemFactory;

$root = dirname(__DIR__);

require_once $root . '/vendor/autoload.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';

$fs = FileSystemFactory::create();
$registry = new PhpArrayFileRegistry();

$dir = $root . '/src/Entity';
if (is_dir($dir)) {
FileSystemHelper::remove(new SplFileInfo($dir));
}
mkdir($dir, 0777, true);
$fs->mkdirIfNotExist($dir);
$fs->emptyDir($dir);
$dirObject = new SplFileInfo($dir);
$namespace = 'Liquetsoft\\Fias\\Elastic\\Entity';
$generator = new ModelGenerator($registry);
$generator->run($dirObject, $namespace);

$dir = $root . '/tests/Entity';
if (is_dir($dir)) {
FileSystemHelper::remove(new SplFileInfo($dir));
}
mkdir($dir, 0777, true);
$fs->mkdirIfNotExist($dir);
$fs->emptyDir($dir);
$dirObject = new SplFileInfo($dir);
$namespace = 'Liquetsoft\\Fias\\Elastic\\Tests\\Entity';
$generator = new ModelTestGenerator($registry);
$generator->run($dirObject, $namespace);

$dir = $root . '/src/IndexMapper';
if (is_dir($dir)) {
FileSystemHelper::remove(new SplFileInfo($dir));
}
mkdir($dir, 0777, true);
$fs->mkdirIfNotExist($dir);
$fs->emptyDir($dir);
$dirObject = new SplFileInfo($dir);
$namespace = 'Liquetsoft\\Fias\\Elastic\\IndexMapper';
$generator = new MapperGenerator($registry);
$generator->run($dirObject, $namespace);

$dir = $root . '/tests/IndexMapper';
if (is_dir($dir)) {
FileSystemHelper::remove(new SplFileInfo($dir));
}
mkdir($dir, 0777, true);
$fs->mkdirIfNotExist($dir);
$fs->emptyDir($dir);
$dirObject = new SplFileInfo($dir);
$namespace = 'Liquetsoft\\Fias\\Elastic\\Tests\\IndexMapper';
$generator = new MapperTestGenerator($registry);
$generator->run($dirObject, $namespace);

$dir = new SplFileInfo($root . '/src/Serializer');
if (is_dir($dir)) {
FileSystemHelper::remove(new SplFileInfo($dir));
}
mkdir($dir, 0777, true);
$fs->mkdirIfNotExist($dir);
$fs->emptyDir($dir);
$namespace = 'Liquetsoft\\Fias\\Elastic\\Serializer';
$generator = new SerializerGenerator($registry);
$generator->run($dir, $namespace);
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
>
<projectFiles>
<directory name="./src" />
<directory name="./generator" />
<ignoreFiles>
</ignoreFiles>
</projectFiles>
Expand Down

0 comments on commit b8ef5e7

Please sign in to comment.