Skip to content

Commit

Permalink
Use Enum to enforce stricter types (⚠ php 8.1) (LycheeOrg#1618)
Browse files Browse the repository at this point in the history
* use Enum
* fix tests & phpstan
* support Severity Type
* more lax values for ASC DESC
* Change FULL for ORIGINAL + DonwloadVariantType enum
  • Loading branch information
ildyria authored Dec 26, 2022
1 parent 26b5393 commit 5a4c154
Show file tree
Hide file tree
Showing 92 changed files with 959 additions and 977 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1

- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --verbose --diff --dry-run

phpstan:
name: 2️⃣ PHP 8.0 - PHPStan
name: 2️⃣ PHP 8.1 - PHPStan
runs-on: ubuntu-latest
needs:
- php_syntax_errors
Expand All @@ -81,9 +81,8 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
coverage: none
tools: phpstan

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
Expand All @@ -99,7 +98,6 @@ jobs:
strategy:
matrix:
php-version:
- 8.0
- 8.1
- 8.2
sql-versions:
Expand Down Expand Up @@ -181,7 +179,6 @@ jobs:
strategy:
matrix:
php-version:
- 8.0
- 8.1
- 8.2
sql-versions:
Expand Down Expand Up @@ -275,7 +272,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
extensions: ${{ env.extensions }}
coverage: none

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
coverage: none
- name: Install PHP-CS-Fixer
run: |
curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.11.0/php-cs-fixer.phar -o .github/build/php-cs-fixer
curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.13.0/php-cs-fixer.phar -o .github/build/php-cs-fixer
chmod a+x .github/build/php-cs-fixer
- name: Prepare Git User
run: |
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center"><a href="https://lycheeorg.github.io"><img src="https://raw.githubusercontent.com/LycheeOrg/Lychee/master/Banner.png" width="400px" alt="@LycheeOrg"></a></p>

[![GitHub Release][release-shield]](https://github.com/LycheeOrg/Lychee/releases)
[![PHP 8.0 & 8.1][php-shield]](https://lycheeorg.github.io/docs/#server-requirements)
[![PHP 8.1 & 8.2][php-shield]](https://lycheeorg.github.io/docs/#server-requirements)
[![MIT License][license-shield]](https://github.com/LycheeOrg/Lychee/blob/master/LICENSE)
[![Downloads][download-shield]](https://github.com/LycheeOrg/Lychee/releases)
<br>
Expand Down Expand Up @@ -32,7 +32,7 @@ Lychee is a free photo-management tool, which runs on your server or web-space.

## Installation

To run Lychee, everything you need is a web-server with PHP 8.0 or later and a MySQL-Database. Follow the instructions to install Lychee on your server. This version of Lychee is built on the Laravel framework. To install:
To run Lychee, everything you need is a web-server with PHP 8.1 or later and a database (MySQL/MariaDB, PostgreSQL or SQLite). Follow the instructions to install Lychee on your server. This version of Lychee is built on the Laravel framework. To install:

1. Clone this repo to your server and set the web root to `lychee/public`
2. Run `composer install --no-dev` to install dependencies
Expand Down Expand Up @@ -96,7 +96,7 @@ We would like to thank Jetbrains for supporting us with their [Open Source Devel
[build-status-shield]: https://img.shields.io/github/actions/workflow/status/LycheeOrg/Lychee/CICD.yml?branch=master
[codecov-shield]: https://codecov.io/gh/LycheeOrg/Lychee/branch/master/graph/badge.svg
[release-shield]: https://img.shields.io/github/release/LycheeOrg/Lychee.svg
[php-shield]: https://img.shields.io/badge/PHP-8.0%20|%208.1-blue
[php-shield]: https://img.shields.io/badge/PHP-8.1%20|%208.2-blue
[license-shield]: https://img.shields.io/github/license/LycheeOrg/Lychee.svg
[cii-shield]: https://img.shields.io/cii/summary/2855.svg
[sonar-shield]: https://sonarcloud.io/api/project_badges/measure?project=LycheeOrg_Lychee-Laravel&metric=alert_status
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Album/PositionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use App\Contracts\Models\AbstractAlbum;
use App\DTO\PositionData as PositionDataDTO;
use App\Enum\SizeVariantType;
use App\Models\Album;
use App\Models\SizeVariant;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

Expand Down Expand Up @@ -33,7 +33,7 @@ public function get(AbstractAlbum $album, bool $includeSubAlbums = false): Posit
// this really helps, if you want to show thousands
// of photos on a map, as there are up to 7 size
// variants per photo
$r->whereBetween('type', [SizeVariant::SMALL2X, SizeVariant::THUMB]);
$r->whereBetween('type', [SizeVariantType::SMALL2X, SizeVariantType::THUMB]);
},
'size_variants.sym_links',
])
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Albums/PositionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Contracts\Exceptions\InternalLycheeException;
use App\DTO\PositionData as PositionDataDTO;
use App\Enum\SizeVariantType;
use App\Models\Configs;
use App\Models\Photo;
use App\Models\SizeVariant;
use App\Policies\PhotoQueryPolicy;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function do(): PositionDataDTO
// this really helps, if you want to show thousands
// of photos on a map, as there are up to 7 size
// variants per photo
$r->whereBetween('type', [SizeVariant::SMALL2X, SizeVariant::THUMB]);
$r->whereBetween('type', [SizeVariantType::SMALL2X, SizeVariantType::THUMB]);
},
'size_variants.sym_links',
])
Expand Down
4 changes: 3 additions & 1 deletion app/Actions/Albums/Top.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\Contracts\Exceptions\InternalLycheeException;
use App\DTO\AlbumSortingCriterion;
use App\DTO\TopAlbums;
use App\Enum\ColumnSortingType;
use App\Enum\OrderSortingType;
use App\Exceptions\ConfigurationKeyMissingException;
use App\Exceptions\Internal\InvalidOrderDirectionException;
use App\Factories\AlbumFactory;
Expand Down Expand Up @@ -86,7 +88,7 @@ public function get(): TopAlbums
if ($userID !== null) {
// For authenticated users we group albums by ownership.
$albums = (new SortingDecorator($query))
->orderBy('owner_id')
->orderBy(ColumnSortingType::OWNER_ID, OrderSortingType::ASC)
->orderBy($this->sorting->column, $this->sorting->order)
->get();

Expand Down
4 changes: 3 additions & 1 deletion app/Actions/Albums/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\Contracts\Exceptions\InternalLycheeException;
use App\DTO\AlbumSortingCriterion;
use App\DTO\AlbumTree;
use App\Enum\ColumnSortingType;
use App\Enum\OrderSortingType;
use App\Exceptions\ConfigurationKeyMissingException;
use App\Exceptions\Internal\InvalidOrderDirectionException;
use App\Models\Album;
Expand Down Expand Up @@ -55,7 +57,7 @@ public function get(): AlbumTree
);
if (Auth::check()) {
// For authenticated users we group albums by ownership.
$query->orderBy('owner_id');
$query->orderBy(ColumnSortingType::OWNER_ID, OrderSortingType::ASC);
}
$query->orderBy($this->sorting->column, $this->sorting->order);

Expand Down
10 changes: 3 additions & 7 deletions app/Actions/Diagnostics/Pipes/Checks/PHPVersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ private function checkPhpVersion(array &$data): void
// 26 Nov 2020 => 8.0 = RELEASED => 7.4 = WARNING
// 6 Dec 2020 => 7.3 = DEPRECATED = ERROR
// 25 Nov 2021 => 8.1 = Released => 8.0 = WARNING & 7.4 = ERROR
$php_error = 7.4;
$php_warning = 8;
$php_latest = 8.1;

// ! 08 Dec 2022 => 8.0 = DEPRECATED = ERROR
// $php_error = 8.1;
// $php_warning = 8.1;
// $php_latest = 8.2;
$php_error = 8.0;
$php_warning = 8.1;
$php_latest = 8.2;

if (floatval(phpversion()) <= $php_error) {
$data[] = 'Error: Upgrade to PHP ' . $php_warning . ' or higher';
Expand Down
17 changes: 9 additions & 8 deletions app/Actions/InstallUpdate/CheckUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\Diagnostics\Pipes\Checks\MigrationCheck;
use App\Actions\Diagnostics\Pipes\Checks\UpdatableCheck;
use App\Enum\UpdateStatus;
use App\Metadata\Versions\FileVersion;
use App\Metadata\Versions\GitHubVersion;
use App\Metadata\Versions\InstalledVersion;
Expand Down Expand Up @@ -33,16 +34,16 @@ public function __construct(
* - `2` - Not up-to-date.
* - `3` - Require migration.
*
* @return int the update state between 0..3
* @return UpdateStatus the update state between 0..3
*/
public function getCode(): int
public function getCode(): UpdateStatus
{
if ($this->installedVersion->isRelease()) {
// @codeCoverageIgnoreStart
return match (false) {
MigrationCheck::isUpToDate() => 3,
$this->fileVersion->isUpToDate() => 2,
default => 1
MigrationCheck::isUpToDate() => UpdateStatus::REQUIRE_MIGRATION,
$this->fileVersion->isUpToDate() => UpdateStatus::NOT_UP_TO_DATE,
default => UpdateStatus::UP_TO_DATE
};
// @codeCoverageIgnoreEnd
}
Expand All @@ -51,13 +52,13 @@ public function getCode(): int
UpdatableCheck::assertUpdatability();
// @codeCoverageIgnoreStart
if (!$this->gitHubFunctions->isUpToDate()) {
return 2;
return UpdateStatus::NOT_UP_TO_DATE;
} else {
return 1;
return UpdateStatus::UP_TO_DATE;
}
// @codeCoverageIgnoreEnd
} catch (\Exception $e) {
return 0;
return UpdateStatus::NOT_MASTER;
}
}
}
Loading

0 comments on commit 5a4c154

Please sign in to comment.