Skip to content

Commit 3f9aa75

Browse files
authored
Update php to 8 (#32)
* update php to 8 and fix * replace file system helper with external lib
1 parent 87b2521 commit 3f9aa75

File tree

15 files changed

+89
-234
lines changed

15 files changed

+89
-234
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.3', '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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ composer.lock
77
tests/coverage
88
docker/.env
99
test.php
10+
generator/extracted
11+
generator/archive
1012

1113
.~lock.*

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ coverage: ## Run tests with coverage
3333
xsd: ## Build entities from yaml file with description
3434
$(php_container_bin) composer run-script xsd
3535

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

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"keywords": ["php", "fias"],
66
"license": "MIT",
77
"require": {
8-
"php": ">=7.2",
8+
"php": ">=7.3",
99
"ext-soap": "*",
1010
"ext-libxml": "*",
1111
"ext-xmlreader": "*",
@@ -17,11 +17,12 @@
1717
"symfony/property-info": "^4.0|^5.0",
1818
"psr/log": "^1.1",
1919
"ramsey/uuid": "^3.0|^4.0",
20-
"symfony/process": "^4.0|^5.0"
20+
"symfony/process": "^4.0|^5.0",
21+
"marvin255/file-system-helper": "^1.1"
2122
},
2223
"require-dev": {
2324
"phpunit/phpunit": "^7.0|^8.0|^9.0",
24-
"fzaninotto/faker": "^1.7",
25+
"fakerphp/faker": "^1.7",
2526
"friendsofphp/php-cs-fixer": "^2.16",
2627
"sebastian/phpcpd": "^4.0|^5.0|^6.0",
2728
"vimeo/psalm": "^4.0"
@@ -43,8 +44,8 @@
4344
"coverage": "vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-html=tests/coverage",
4445
"fixer": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v",
4546
"linter": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation && vendor/bin/phpcpd ./ --exclude vendor --exclude resources --exclude tests && vendor/bin/psalm --show-info=true",
46-
"xsd": "php -f generator/download_entites.php",
47-
"entites": "php -f generator/generate_entities.php && vendor/bin/php-cs-fixer fix --config=.php_cs.dist -q"
47+
"xsd": "php -f generator/download_entities.php",
48+
"entities": "php -f generator/generate_entities.php && vendor/bin/php-cs-fixer fix --config=.php_cs.dist -q"
4849
},
4950
"repositories": [
5051
{

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/download_entites.php renamed to generator/download_entities.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
use Liquetsoft\Fias\Component\Downloader\CurlDownloader;
44
use Liquetsoft\Fias\Component\FiasInformer\SoapFiasInformer;
5-
use Liquetsoft\Fias\Component\Helper\FileSystemHelper;
65
use Liquetsoft\Fias\Component\Helper\PathHelper;
76
use Liquetsoft\Fias\Component\Unpacker\ZipUnpacker;
7+
use Marvin255\FileSystemHelper\FileSystemFactory;
88

99
require_once dirname(__DIR__) . '/vendor/autoload.php';
1010

11+
$fs = FileSystemFactory::create();
1112
$informer = new SoapFiasInformer();
1213
$downloader = new CurlDownloader();
1314
$unpack = new ZipUnpacker();
@@ -16,11 +17,9 @@
1617
$tmpDir = new SplFileInfo("{$sysTmp}/extracted");
1718
$xsdFolder = new SplFileInfo(PathHelper::resource('xsd'));
1819

19-
FileSystemHelper::remove($tmpFile);
20-
FileSystemHelper::remove($tmpDir);
21-
if (!mkdir($tmpDir->getPathname(), 0777, true)) {
22-
throw new RuntimeException("Can't create temp dir.");
23-
}
20+
$fs->removeIfExists($tmpFile);
21+
$fs->mkdirIfNotExist($tmpDir);
22+
$fs->emptyDir($tmpDir);
2423

2524
$deltas = $informer->getDeltaList();
2625
$version = reset($deltas);
@@ -31,7 +30,7 @@
3130
$downloader->download($version->getUrl(), $tmpFile);
3231
$unpack->unpack($tmpFile, $tmpDir);
3332

34-
FileSystemHelper::remove($xsdFolder);
35-
FileSystemHelper::move(new SplFileInfo($tmpDir->getPathname() . '/Schemas'), $xsdFolder);
36-
FileSystemHelper::remove($tmpDir);
37-
FileSystemHelper::remove($tmpFile);
33+
$fs->removeIfExists($xsdFolder);
34+
$fs->rename($tmpDir->getPathname() . '/Schemas', $xsdFolder);
35+
$fs->removeIfExists($tmpDir);
36+
$fs->removeIfExists($tmpFile);

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="tests/bootstrap.php"
3+
<phpunit bootstrap="vendor/autoload.php"
44
colors="true"
55
beStrictAboutTestsThatDoNotTestAnything="true">
66

src/Downloader/CurlDownloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function download(string $url, SplFileInfo $localFile): void
6060
protected function curlDownload(array $requestOptions): array
6161
{
6262
$ch = curl_init();
63-
if (!is_resource($ch)) {
63+
if ($ch === false) {
6464
throw new DownloaderException("Can't init curl resource.");
6565
}
6666

src/Helper/FileSystemHelper.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/Pipeline/Task/CleanupTask.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace Liquetsoft\Fias\Component\Pipeline\Task;
66

7-
use Liquetsoft\Fias\Component\Helper\FileSystemHelper;
87
use Liquetsoft\Fias\Component\Pipeline\State\State;
8+
use Marvin255\FileSystemHelper\FileSystemFactory;
9+
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
910
use Psr\Log\LogLevel;
1011
use SplFileInfo;
1112

@@ -16,6 +17,16 @@ class CleanupTask implements Task, LoggableTask
1617
{
1718
use LoggableTaskTrait;
1819

20+
/**
21+
* @var FileSystemHelperInterface
22+
*/
23+
private $fs;
24+
25+
public function __construct()
26+
{
27+
$this->fs = FileSystemFactory::create();
28+
}
29+
1930
/**
2031
* {@inheritDoc}
2132
*/
@@ -31,7 +42,7 @@ public function run(State $state): void
3142
foreach ($toRemove as $fileInfo) {
3243
if ($fileInfo instanceof SplFileInfo) {
3344
$this->log(LogLevel::INFO, "Cleaning up '{$fileInfo->getRealPath()}' folder.");
34-
FileSystemHelper::remove($fileInfo);
45+
$this->fs->removeIfExists($fileInfo);
3546
}
3647
}
3748
}

src/Pipeline/Task/PrepareFolderTask.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Liquetsoft\Fias\Component\Pipeline\Task;
66

77
use InvalidArgumentException;
8-
use Liquetsoft\Fias\Component\Exception\TaskException;
9-
use Liquetsoft\Fias\Component\Helper\FileSystemHelper;
108
use Liquetsoft\Fias\Component\Pipeline\State\State;
9+
use Marvin255\FileSystemHelper\FileSystemFactory;
10+
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
1111
use Psr\Log\LogLevel;
1212
use SplFileInfo;
1313

@@ -24,6 +24,11 @@ class PrepareFolderTask implements Task, LoggableTask
2424
*/
2525
protected $folder;
2626

27+
/**
28+
* @var FileSystemHelperInterface
29+
*/
30+
private $fs;
31+
2732
/**
2833
* @param string $folder
2934
*
@@ -41,29 +46,23 @@ public function __construct(string $folder)
4146
}
4247

4348
$this->folder = new SplFileInfo($trimmedFolder);
49+
$this->fs = FileSystemFactory::create();
4450
}
4551

4652
/**
4753
* {@inheritDoc}
4854
*/
4955
public function run(State $state): void
5056
{
51-
if ($this->folder->isDir()) {
52-
$this->log(LogLevel::INFO, "Emptying '{$this->folder->getRealPath()}' folder.");
53-
FileSystemHelper::remove($this->folder);
54-
}
55-
56-
if (!mkdir($this->folder->getPathname())) {
57-
throw new TaskException("Can't create '" . $this->folder->getPathname() . "' folder.");
58-
}
57+
$this->log(LogLevel::INFO, "Emptying '{$this->folder->getRealPath()}' folder.");
58+
$this->fs->mkdirIfNotExist($this->folder);
59+
$this->fs->emptyDir($this->folder);
5960

6061
$downloadToFile = new SplFileInfo($this->folder->getRealPath() . '/archive');
6162
$extractToFolder = new SplFileInfo($this->folder->getRealPath() . '/extracted');
6263

6364
$this->log(LogLevel::INFO, "Creating '{$this->folder->getRealPath()}/extracted' folder.");
64-
if (!mkdir($extractToFolder->getPathname())) {
65-
throw new TaskException("Can't create '" . $extractToFolder->getPathname() . "' folder.");
66-
}
65+
$this->fs->mkdir($extractToFolder);
6766

6867
$state->setAndLockParameter(Task::DOWNLOAD_TO_FILE_PARAM, $downloadToFile);
6968
$state->setAndLockParameter(Task::EXTRACT_TO_FOLDER_PARAM, $extractToFolder);

src/Pipeline/Task/SaveFiasFilesTask.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace Liquetsoft\Fias\Component\Pipeline\Task;
66

7-
use Liquetsoft\Fias\Component\Helper\FileSystemHelper;
87
use Liquetsoft\Fias\Component\Pipeline\State\State;
8+
use Marvin255\FileSystemHelper\FileSystemFactory;
9+
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
910
use Psr\Log\LogLevel;
1011
use SplFileInfo;
1112

@@ -22,6 +23,11 @@ class SaveFiasFilesTask implements Task, LoggableTask
2223
*/
2324
protected $movePaths;
2425

26+
/**
27+
* @var FileSystemHelperInterface
28+
*/
29+
private $fs;
30+
2531
/**
2632
* @param string|null $moveArchiveTo
2733
* @param string|null $moveExtractedTo
@@ -37,6 +43,8 @@ public function __construct(?string $moveArchiveTo, ?string $moveExtractedTo)
3743
if ($moveExtractedTo !== null) {
3844
$this->movePaths[Task::EXTRACT_TO_FOLDER_PARAM] = $moveExtractedTo;
3945
}
46+
47+
$this->fs = FileSystemFactory::create();
4048
}
4149

4250
/**
@@ -54,7 +62,7 @@ public function run(State $state): void
5462
$message = sprintf("Moving '%s' to '%s'.", $fileInfo->getRealPath(), $movePath);
5563
$this->log(LogLevel::INFO, $message);
5664

57-
FileSystemHelper::move($fileInfo, new SplFileInfo($movePath));
65+
$this->fs->rename($fileInfo, $movePath);
5866
}
5967
}
6068
}

tests/bootstrap.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)