Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/phan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Phan

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

permissions:
contents: read

jobs:
phan:
name: Phan
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'

- name: Install dependencies
run: composer install --no-interaction --prefer-dist --no-progress

- name: Run Phan
run: composer analyze
20 changes: 20 additions & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

return [
'target_php_version' => '8.4',
'directory_list' => [
'src',
'vendor/filp/whoops/src',
'vendor/guzzlehttp/psr7/src',
'vendor/psr/http-message/src',
'vendor/psr/http-server-handler/src',
'vendor/twig/twig/src',
],
'exclude_analysis_directory_list' => [
'vendor',
],
'exclude_file_regex' => '@^vendor/.*/(?:tests?|Tests?)/@',
'suppress_issue_types' => [
'PhanUnreferencedUseNormal',
],
];
98 changes: 98 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

$header = <<<EOF
This file is part of the Divergence package.

(c) Henry Paradiz <henry.paradiz@gmail.com>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

$headerRule = [
'header' => $header,
'validator' => '/' . preg_quote($header, '/') . '(?P<EXTRA>.*)??/s',
'comment_type' => 'PHPDoc',
'location' => 'after_open',
'separate' => 'none',
];

$headerPolicy = new class($headerRule) implements PhpCsFixer\Config\RuleCustomisationPolicyInterface {
private array $headerRule;
private string $headerPrefix;

public function __construct(array $headerRule)
{
$this->headerRule = $headerRule;
$this->headerPrefix = "<?php\n/**\n" . implode("\n", array_map(
static fn (string $line): string => rtrim(' * ' . $line),
explode("\n", $headerRule['header'])
)) . "\n";
}

public function getPolicyVersionForCache(): string
{
return 'preserve-header-separation-v3';
}

public function getRuleCustomisers(): array
{
return [
'header_comment' => $this->customizeHeaderComment(...),
];
}

private function customizeHeaderComment(SplFileInfo $file): bool|PhpCsFixer\Fixer\FixerInterface
{
$contents = file_get_contents($file->getPathname());

if (false !== $contents && str_starts_with(str_replace("\r", '', $contents), $this->headerPrefix)) {
return false;
}

$headerRule = $this->headerRule;

if (false !== $contents && preg_match('/\A<\?php\R(?<doc>\/\*\*.*?\*\/)(?<separator>\R*)/s', $contents, $matches)) {
$lines = array_slice(explode("\n", str_replace("\r", '', $matches['doc'])), 1, -1);
$extra = implode("\n", array_map(
static fn (string $line): string => ' *' === $line ? '' : (str_starts_with($line, ' * ') ? substr($line, 3) : $line),
$lines
));

if ('' !== trim($extra)) {
$headerRule['header'] .= "\n\n" . $extra;
}

if (1 < substr_count(str_replace("\r", '', $matches['separator']), "\n")) {
$headerRule['separate'] = 'bottom';
}
}

$fixer = new PhpCsFixer\Fixer\Comment\HeaderCommentFixer();
$fixer->configure($headerRule);

return $fixer;
}
};

$finder = (new PhpCsFixer\Finder())
//->exclude('somedir')
->in(__DIR__)
;

return (new PhpCsFixer\Config())
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'no_break_comment' => false,
'array_syntax' => ['syntax' => 'short'],
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'no_trailing_comma_in_singleline' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'indentation_type' => true,
'header_comment' => $headerRule,
])
->setRuleCustomisationPolicy($headerPolicy)
->setFinder($finder)
;
39 changes: 0 additions & 39 deletions .php_cs.dist.php

This file was deleted.

13 changes: 12 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
checks:
php:
argument_type_checks: false
code_rating: true
duplication: true
fix_doc_comments: false
no_exit: false
unused_parameters: false
unused_properties: false
unused_variables: false
use_statement_alias_conflict: false
verify_property_names: false

build:
image: default-jammy
environment:
php: 8.4.11
php:
version: 8.4.11
ini:
memory_limit: "512M"
nodes:
coverage:
services:
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
"phpunit/phpcov": "^12.0",
"friendsofphp/php-cs-fixer": "*",
"mikey179/vfsstream": "^1.6",
"fakerphp/faker": "^1.20"
"fakerphp/faker": "^1.20",
"phan/phan": "^6.0"
},
"suggest": {
"divergence/cli": "Lets you initialize a new project as well as create, edit, and test database configurations via CLI."
},
"scripts": {
"analyze": "phan --allow-polyfill-parser --no-progress-bar",
"fix-code": "php-cs-fixer fix",
"test": [
"@test:mysql",
Expand Down
10 changes: 10 additions & 0 deletions src/Controllers/Media/Endpoints/Browse.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @phan-file-suppress PhanUndeclaredClassMethod
*/

namespace Divergence\Controllers\Media\Endpoints;

Expand Down
9 changes: 8 additions & 1 deletion src/Controllers/Media/Endpoints/Caption.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down
9 changes: 8 additions & 1 deletion src/Controllers/Media/Endpoints/Delete.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down
12 changes: 11 additions & 1 deletion src/Controllers/Media/Endpoints/Download.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down Expand Up @@ -41,6 +48,9 @@ public function handle(...$arguments): ResponseInterface
}

$filePath = $Media->getFilesystemPath('original');
if ($filePath === null) {
return $this->handler->throwNotFoundError();
}
$this->handler->responseBuilder = MediaBuilder::class;
$response = $this->handler->respondWithMedia($Media, 'original', $filePath);

Expand Down
9 changes: 8 additions & 1 deletion src/Controllers/Media/Endpoints/Info.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down
13 changes: 12 additions & 1 deletion src/Controllers/Media/Endpoints/Media.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down Expand Up @@ -66,6 +73,10 @@ public function handle(...$arguments): ResponseInterface
set_time_limit(0);
$filePath = $Media->getFilesystemPath($variant);

if ($filePath === null) {
return $this->handler->throwNotFoundError();
}

if (!empty($_server['HTTP_IF_NONE_MATCH']) || !empty($_server['HTTP_IF_MODIFIED_SINCE'])) {
$this->handler->responseBuilder = EmptyBuilder::class;
$response = $this->handler->respondEmpty($filePath);
Expand Down
11 changes: 9 additions & 2 deletions src/Controllers/Media/Endpoints/MediaDelete.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down Expand Up @@ -39,7 +46,7 @@ public function handle(...$arguments): ResponseInterface

$deleted = [];
foreach ($mediaArray as $mediaId => $Media) {
if ($Media->delete()) {
if ($Media->destroy()) {
$deleted[] = $mediaId;
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/Controllers/Media/Endpoints/Thumbnail.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Divergence\Controllers\Media\Endpoints;

use Divergence\Controllers\Media\AbstractMediaEndpoint;
Expand Down Expand Up @@ -41,7 +48,8 @@ public function handle(...$arguments): ResponseInterface
return $response;
}

if (preg_match('/^(\d+)x(\d+)(x([0-9A-F]{6})?)?$/i', $this->handler->peekPath(), $matches)) {
$size = $this->handler->peekPath();
if (is_string($size) && preg_match('/^(\d+)x(\d+)(x([0-9A-F]{6})?)?$/i', $size, $matches)) {
$this->handler->shiftPath();
$maxWidth = $matches[1];
$maxHeight = $matches[2];
Expand All @@ -62,7 +70,7 @@ public function handle(...$arguments): ResponseInterface
$thumbPath = $Media->getThumbnail($maxWidth, $maxHeight, $fillColor, $cropped);
$this->handler->responseBuilder = MediaBuilder::class;

return $this->handler->respondWithThumbnail($Media, "$maxWidth-$maxHeight-$fillColor-$cropped", $thumbPath);
return $this->handler->respondWithThumbnail($Media, "$maxWidth-$maxHeight-$fillColor-".(int)$cropped, $thumbPath);
} catch (Exception $e) {
return $this->handler->throwNotFoundError();
}
Expand Down
Loading
Loading