Skip to content

Commit

Permalink
ci: remove support for PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Dec 20, 2023
1 parent cb97193 commit 22c36ea
Show file tree
Hide file tree
Showing 26 changed files with 225 additions and 127 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
strategy:
matrix:
include:
- php-versions: "8.0"
- php-versions: "8.1"
- php-versions: "8.2"
stable: true
Expand All @@ -40,7 +39,7 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: ⚙️ Install dependencies
Expand All @@ -52,24 +51,18 @@ jobs:
uses: actions/cache@v3
with:
path: tools/cache
key: ${{ runner.os }}-test-${{ github.sha }}
key: ${{ runner.os }}-tools-${{ matrix.php-versions }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-test-
${{ runner.os }}-tools-
- name: 👕 Lint
if: matrix.stable
run: composer php-cs-fixer -- --format=checkstyle | tools/vendor/bin/cs2pr

- name: 🔬 Static analysis
if: matrix.stable
run: composer stan -- --error-format=checkstyle | tools/vendor/bin/cs2pr

- name: ♻️ Test cache
uses: actions/cache@v3
with:
path: tests/.phpunit.result.cache
key: ${{ runner.os }}-test-${{ github.sha }}
restore-keys: |
${{ runner.os }}-test-
- name: 🧪 Test
run: composer test:ci

Expand All @@ -80,7 +73,7 @@ jobs:
file: ./build/logs/clover.xml

- name: 📃 Generate documentation
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.stable == 'true'
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.stable
env:
GITHUB_TOKEN: ${{ secrets.GH_PRIVATE_ACCESS_TOKEN }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"twitter/bootstrap": "Twitter bootstrap assets"
},
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"php": "~8.1.0 || ~8.2.0",
"laminas/laminas-escaper": "^2.12",
"laminas/laminas-form": "^3.4",
"laminas/laminas-i18n": "^2.17",
Expand Down
6 changes: 3 additions & 3 deletions scripts/generateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
$rootDirPath,
$testsDirPath,
$bootstrapVersionResolver->getBootstrapVersion(),
$maxNestedDir
$maxNestedDir,
$file
);


$homePageGenerator = new \Documentation\Generator\HomePageGenerator($configuration, $file);
$homePageGenerator = new \Documentation\Generator\HomePageGenerator($configuration);
$homePageGenerator->generate();

$testConfigsLoader = new \Documentation\Test\ConfigsLoader($testsDirPath);

$usagePagesGenerator = new \Documentation\Generator\UsagePage\UsagePagesGenerator(
$configuration,
$file,
$testConfigsLoader->loadDocumentationTestConfigs(),
);
$usagePagesGenerator->generate();
14 changes: 13 additions & 1 deletion src/Documentation/Generator/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ class Configuration
*/
private $maxNestedDir;

/**
* @var \Documentation\Generator\FileSystem\File
*/
private $file;

public function __construct(
$rootDirPath,
$testsDirPath,
$bootstrapVersion,
$maxNestedDir
$maxNestedDir,
$file
) {
$this->rootDirPath = $rootDirPath;
$this->testsDirPath = $testsDirPath;
$this->bootstrapVersion = $bootstrapVersion;
$this->maxNestedDir = $maxNestedDir;
$this->file = $file;
}

public function getRootDirPath()
Expand All @@ -55,4 +62,9 @@ public function getMaxNestedDir()
{
return $this->maxNestedDir;
}

public function getFile()
{
return $this->file;
}
}
4 changes: 4 additions & 0 deletions src/Documentation/Generator/FileSystem/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public function readFile($filePath);

public function writeFile($filePath, $fileContent);

public function writeTmpFile($fileName, $fileContent);

public function appendFile($filePath, $fileContent);

public function removeFile($filePath);
}
19 changes: 18 additions & 1 deletion src/Documentation/Generator/FileSystem/Local/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function dirExists($dirPath)
public function removeDir($dirPath)
{
if (!$this->dirExists($dirPath)) {
throw new \InvalidArgumentException('Argument "$dirPath" is not an existing directory path');
throw new \InvalidArgumentException('Given directory path "' . $dirPath . '" is not an existing directory path');
}

$dirObj = new \RecursiveDirectoryIterator($dirPath, \RecursiveDirectoryIterator::SKIP_DOTS);
Expand All @@ -38,8 +38,25 @@ public function writeFile($filePath, $fileContent)
file_put_contents($filePath, $fileContent);
}

public function writeTmpFile($fileName, $fileContent)
{
$tmpFile = tempnam(sys_get_temp_dir(), $fileName);
$this->writeFile($tmpFile, $fileContent);
return $tmpFile;
}

public function appendFile($filePath, $fileContent)
{
file_put_contents($filePath, $fileContent, FILE_APPEND);
}


public function removeFile($filePath)
{
if (!$this->fileExists($filePath)) {
throw new \InvalidArgumentException('Given file path does "' . $filePath . '" not exists');
}

unlink($filePath);
}
}
16 changes: 6 additions & 10 deletions src/Documentation/Generator/HomePageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@ class HomePageGenerator
*/
private $configuration;

/**
* @var \Documentation\Generator\FileSystem\File
*/
private $file;

public function __construct(
\Documentation\Generator\Configuration $configuration,
\Documentation\Generator\FileSystem\File $file
\Documentation\Generator\Configuration $configuration
) {
$this->configuration = $configuration;
$this->file = $file;
}

public function generate()
{
$readmePath = $this->configuration->getRootDirPath() . DIRECTORY_SEPARATOR . self::$README_FILEPATH;
$readmeContent = $this->file->readFile($readmePath);

$this->file->writeFile(
$file = $this->configuration->getFile();

$readmeContent = $file->readFile($readmePath);

$file->writeFile(
self::$HOMEPAGE_FILEPATH,
'---' . PHP_EOL . 'title: Home' . PHP_EOL . '---' . PHP_EOL . PHP_EOL . $readmeContent
);
Expand Down
69 changes: 42 additions & 27 deletions src/Documentation/Generator/UsagePage/Prettifier/PhpPrettifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ class PhpPrettifier
private static $CONFIGURATION_FILE = '.php-cs-fixer.dist.php';
private static $instance = null;

private $configurationPath = '.php-cs-fixer.dist.php';
/**
* @var \Documentation\Generator\FileSystem\File
*/
private $file;

/**
* @var \PhpCsFixer\Console\Application
*/
private $application;

private $configurationPath;


private function __construct(\Documentation\Generator\Configuration $configuration)
{
$this->file = $configuration->getFile();
$this->configurationPath = $configuration->getRootDirPath() . DIRECTORY_SEPARATOR . self::$CONFIGURATION_FILE;

$this->application = new Application();
Expand All @@ -33,39 +44,43 @@ public static function getInstance(
return static::$instance;
}


public function prettify($source)
{
// Write source to temporary file
$tmpFile = tempnam(sys_get_temp_dir(), 'phpcsfixer');
file_put_contents($tmpFile, $source);
$tmpFile = $this->file->writeTmpFile('phpcsfixer', $source);

try {
$input = new \Symfony\Component\Console\Input\ArrayInput(
[
'command' => 'fix',
'path' => [$tmpFile],
'--dry-run' => false,
'--config' => $this->configurationPath,
]
);

$output = new \Symfony\Component\Console\Output\BufferedOutput();

$result = $this->application->run(
$input,
$output
);

if ($result !== 0) {
throw new \RuntimeException('PhpCsFixer failed.' . $output->fetch());
}

$prettyfiedSource = trim(file_get_contents($tmpFile));

$prettyfiedSource = $this->executePhpCsFixer($tmpFile);
return $prettyfiedSource;
} finally {
unlink($tmpFile);
$this->file->removeFile($tmpFile);
}
}

private function executePhpCsFixer($tmpFile)
{
$input = new \Symfony\Component\Console\Input\ArrayInput(
[
'command' => 'fix',
'path' => [$tmpFile],
'--dry-run' => false,
'--config' => $this->configurationPath,
]
);

$output = new \Symfony\Component\Console\Output\BufferedOutput();

$result = $this->application->run(
$input,
$output
);

if ($result !== 0) {
throw new \RuntimeException('PhpCsFixer failed.' . $output->fetch());

Check warning on line 79 in src/Documentation/Generator/UsagePage/Prettifier/PhpPrettifier.php

View check run for this annotation

Codecov / codecov/patch

src/Documentation/Generator/UsagePage/Prettifier/PhpPrettifier.php#L79

Added line #L79 was not covered by tests
}

$prettyfiedSource = trim($this->file->readFile($tmpFile));

return $prettyfiedSource;
}
}
11 changes: 0 additions & 11 deletions src/Documentation/Generator/UsagePage/Prettifier/SourceFile.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private function getRenderingSource()
$phpPrettifier = \Documentation\Generator\UsagePage\Prettifier\PhpPrettifier::getInstance(
$this->configuration
);

return $phpPrettifier->prettify($source);
}

Expand All @@ -66,7 +67,7 @@ private function getRenderResult()
$snapshotService = new \Documentation\Test\SnapshotService($this->configuration->getTestsDirPath());
$snapshotPath = $snapshotService->getSnapshotPathFromTitle($this->testConfig->title);

$snapshotContent = file_get_contents($snapshotPath);
$snapshotContent = $this->configuration->getFile()->readFile($snapshotPath);

Check warning on line 70 in src/Documentation/Generator/UsagePage/Printer/CodePrinter.php

View check run for this annotation

Codecov / codecov/patch

src/Documentation/Generator/UsagePage/Printer/CodePrinter.php#L70

Added line #L70 was not covered by tests
return trim($snapshotContent);
}
}
17 changes: 6 additions & 11 deletions src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ class UsagePageFileGenerator
*/
private $configuration;

/**
* @var \Documentation\Generator\FileSystem\File
*/
private $file;

/**
* @var \Documentation\Test\Config
*/
Expand All @@ -33,11 +28,9 @@ class UsagePageFileGenerator

public function __construct(
\Documentation\Generator\Configuration $configuration,
\Documentation\Generator\FileSystem\File $file,
\Documentation\Test\Config $documentationTestConfig
) {
$this->configuration = $configuration;
$this->file = $file;
$this->documentationTestConfig = $documentationTestConfig;
}

Expand All @@ -50,14 +43,16 @@ public function generate(string $content)
throw new \LogicException('Page directory path is undefined');
}

if (!$this->file->dirExists($pageDirPath)) {
$file = $this->configuration->getFile();

Check warning on line 46 in src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php#L46

Added line #L46 was not covered by tests

if (!$file->dirExists($pageDirPath)) {

Check warning on line 48 in src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php#L48

Added line #L48 was not covered by tests
mkdir($pageDirPath);
$this->generateCategoryFile();
}

if ($content) {
return
$this->file->appendFile(
$file->appendFile(

Check warning on line 55 in src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php#L55

Added line #L55 was not covered by tests
$pagePathInfo->pagePath,
$content,
);
Expand Down Expand Up @@ -102,7 +97,7 @@ private function getUsageDirPath()
{
$usageDirPath = $this->configuration->getRootDirPath() . DIRECTORY_SEPARATOR . self::$USAGE_DIR_PATH;

if (!$this->file->dirExists($usageDirPath)) {
if (!$this->configuration->getFile()->dirExists($usageDirPath)) {
throw new \LogicException('Usage dir path "' . $usageDirPath . '" does not exist');
}

Expand Down Expand Up @@ -141,7 +136,7 @@ private function sanitizePath($path)
private function generateCategoryFile()
{
$pagePathInfo = $this->getPagePathInfo();
$this->file->writeFile(
$this->configuration->getFile()->writeFile(

Check warning on line 139 in src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/Documentation/Generator/UsagePage/UsagePageFileGenerator.php#L139

Added line #L139 was not covered by tests
$pagePathInfo->dirPath . DIRECTORY_SEPARATOR . '_category_.json',
sprintf(
self::$USAGE_PAGE_DIRECTORY_TEMPLATE,
Expand Down
Loading

0 comments on commit 22c36ea

Please sign in to comment.