Skip to content

Commit

Permalink
chore: Bumped
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Feb 10, 2025
1 parent 2f2cd5a commit 58f2d47
Show file tree
Hide file tree
Showing 106 changed files with 4,060 additions and 2,626 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2', '8.3']
php-version: ['8.0', '8.1']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,7 +35,9 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run Unit tests
run: vendor/bin/phpunit -v --whitelist ./src tests
- name: Run atoum unit tests
run: vendor/bin/atoum -d tests
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#
# Roadiz
#
/pimple.json

# Ignore Google webmaster tool verification
/google*.html
Expand Down
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php
sudo: required
php:
- 7.4
- 8.0
- 8.1
- nightly
env:
- XDEBUG_MODE=coverage
install:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev --no-interaction
script:
- vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src
- vendor/bin/atoum -d tests
- vendor/bin/phpstan analyse -c phpstan.neon
jobs:
allow_failures:
- php: nightly
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © 2024 Ambroise Maupate
Copyright © 2023 Ambroise Maupate

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test:
vendor/bin/atoum -d tests
vendor/bin/phpstan analyse -c phpstan.neon
vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src

dev-test:
vendor/bin/atoum -d tests -l

phpcs:
vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src

phpcbf:
vendor/bin/phpcbf --report=full --report-file=./report.txt -p ./src
42 changes: 18 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,42 @@
}
],
"require": {
"php": ">=8.2",
"php": ">=8.0",
"ext-json": "*",
"ext-gd": "*",
"ext-dom": "*",
"ext-zip": "*",
"ext-simplexml": "*",
"ext-fileinfo": "*",
"doctrine/orm": "~2.20.0",
"doctrine/orm": "<2.17",
"enshrined/svg-sanitize": "^0.15",
"guzzlehttp/guzzle": "^7.2.0",
"guzzlehttp/psr7": "^2.0",
"intervention/image": "^2.5",
"league/flysystem": "^3.0",
"monolog/monolog": "^1.24.0 || ^2.1.1",
"symfony/asset": "6.4.*",
"symfony/console": "6.4.*",
"symfony/event-dispatcher": "6.4.*",
"symfony/filesystem": "6.4.*",
"symfony/finder": "6.4.*",
"symfony/http-foundation": "6.4.*",
"symfony/http-client-contracts": "^3.5",
"symfony/options-resolver": "6.4.*",
"symfony/serializer": "6.4.*",
"twig/twig": "^3.16"
"symfony/asset": "5.4.*",
"symfony/console": "5.4.*",
"symfony/event-dispatcher": "5.4.*",
"symfony/filesystem": "5.4.*",
"symfony/finder": "5.4.*",
"symfony/http-foundation": "5.4.*",
"symfony/options-resolver": "5.4.*",
"symfony/serializer": "5.4.*",
"twig/twig": "^3.1"
},
"require-dev": {
"api-platform/metadata": "~3.3.11",
"doctrine/doctrine-bundle": "^2.8.1",
"php-coveralls/php-coveralls": "^2.4",
"atoum/atoum": "^4.0.0",
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.5.3",
"phpstan/phpdoc-parser": "<2",
"phpstan/phpstan-doctrine": "^1.3",
"phpunit/phpunit": "^9.5"
"phpstan/phpstan-doctrine": "^1.3"
},
"autoload": {
"psr-4": {
"RZ\\Roadiz\\Documents\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"RZ\\Roadiz\\Documents\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
Expand All @@ -68,8 +62,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4.x-dev",
"dev-develop": "2.5.x-dev"
"dev-master": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
}
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"
services:
test80:
image: roadiz/php80-runner
working_dir: /build
command: >
bash -c "
composer install -o &&
make test"
volumes:
- ./:/build
13 changes: 13 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength"/>
</rule>
<file>src/</file>
</ruleset>
8 changes: 3 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
parameters:
level: 7
level: max
paths:
- src
excludePaths:
- */node_modules/*
- */bower_components/*
- */static/*
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
- '#Call to an undefined method Doctrine\\Persistence\\ObjectRepository#'
- '#Call to an undefined method Doctrine\\Persistence\\ObjectManager#'
- '#Call to an undefined method Doctrine\\ORM\\EntityRepository#'
Expand All @@ -19,9 +17,9 @@ parameters:
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'
- '#but returns Doctrine\\Common\\Collections\\ReadableCollection<int, [^\>]+>#'
- '#does not accept Doctrine\\Common\\Collections\\ReadableCollection<int, [^\>]+>#'
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
Expand Down
58 changes: 40 additions & 18 deletions src/AbstractDocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AbstractDocumentFactory
public function __construct(
FilesystemOperator $documentsStorage,
DocumentFinderInterface $documentFinder,
?LoggerInterface $logger = null,
?LoggerInterface $logger = null
) {
if (!$documentsStorage instanceof MountManager) {
trigger_error('Document Storage must be a MountManager to address public and private files.', E_USER_WARNING);
Expand All @@ -42,56 +42,69 @@ public function __construct(
$this->logger = $logger ?? new NullLogger();
}

/**
* @return File
*/
public function getFile(): File
{
if (null === $this->file) {
throw new \BadMethodCallException('File should be defined before using it.');
}

return $this->file;
}

/**
* @param File $file
* @return $this
*/
public function setFile(File $file): static
{
$this->file = $file;

return $this;
}

/**
* @return FolderInterface|null
*/
public function getFolder(): ?FolderInterface
{
return $this->folder;
}

/**
* @param FolderInterface|null $folder
* @return $this
*/
public function setFolder(?FolderInterface $folder = null): static
{
$this->folder = $folder;

return $this;
}

/**
* Special case for SVG without XML statement.
*
* @param DocumentInterface $document
*/
protected function parseSvgMimeType(DocumentInterface $document): void
{
if (
('text/plain' === $document->getMimeType() || 'text/html' === $document->getMimeType())
&& preg_match('#\.svg$#', $document->getFilename())
($document->getMimeType() === 'text/plain' || $document->getMimeType() === 'text/html') &&
preg_match('#\.svg$#', $document->getFilename())
) {
$this->logger->debug('Uploaded a SVG without xml declaration. Presuming it’s a valid SVG file.');
$document->setMimeType('image/svg+xml');
}
}

/**
* @return DocumentInterface
*/
abstract protected function createDocument(): DocumentInterface;

/**
* @param DocumentInterface $document
*/
abstract protected function persistDocument(DocumentInterface $document): void;

protected function getHashAlgorithm(): string
Expand All @@ -103,14 +116,14 @@ protected function getHashAlgorithm(): string
* Create a document from UploadedFile, Be careful, this method does not flush, only
* persists current Document.
*
* @param bool $allowEmpty Default false, requires a local file to create new document entity
* @param bool $allowEmpty Default false, requires a local file to create new document entity
* @param bool $allowDuplicates Default false, always import new document even if file already exists
*
* @return null|DocumentInterface
* @throws FilesystemException
*/
public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = false): ?DocumentInterface
{
if (false === $allowEmpty) {
if ($allowEmpty === false) {
// Getter throw exception on null file
$file = $this->getFile();
} else {
Expand All @@ -134,8 +147,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
$existingDocument = $this->documentFinder->findOneByHashAndAlgorithm($fileHash, $this->getHashAlgorithm());
if (null !== $existingDocument) {
if (
$existingDocument->isRaw()
&& null !== $existingDownscaledDocument = $existingDocument->getDownscaledDocument()
$existingDocument->isRaw() &&
null !== $existingDownscaledDocument = $existingDocument->getDownscaledDocument()
) {
$existingDocument = $existingDownscaledDocument;
}
Expand All @@ -147,7 +160,6 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
'File %s already exists with same checksum, do not upload it twice.',
$existingDocument->getFilename()
));

return $existingDocument;
}
}
Expand All @@ -163,8 +175,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
$this->parseSvgMimeType($document);

if (
$document instanceof FileHashInterface
&& false !== $fileHash
$document instanceof FileHashInterface &&
false !== $fileHash
) {
$document->setFileHash($fileHash);
$document->setFileHashAlgorithm($this->getHashAlgorithm());
Expand All @@ -184,6 +196,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
/**
* Updates a document from UploadedFile, Be careful, this method does not flush.
*
* @param DocumentInterface $document
* @return DocumentInterface
* @throws FilesystemException
*/
public function updateDocument(DocumentInterface $document): DocumentInterface
Expand Down Expand Up @@ -217,7 +231,7 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
}
}

$document->setFolder(\mb_substr(hash('crc32b', date('YmdHi')), 0, 12));
$document->setFolder(\mb_substr(hash("crc32b", date('YmdHi')), 0, 12));
}

$document->setFilename($this->getFileName());
Expand All @@ -233,6 +247,9 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
}

/**
* @param File $localFile
* @param DocumentInterface $document
* @return void
* @throws FilesystemException
*/
public function moveFile(File $localFile, DocumentInterface $document): void
Expand All @@ -250,6 +267,9 @@ public function moveFile(File $localFile, DocumentInterface $document): void
}
}

/**
* @return string
*/
protected function getFileName(): string
{
$file = $this->getFile();
Expand All @@ -258,8 +278,8 @@ protected function getFileName(): string
$fileName = $file->getClientOriginalName();
} elseif (
$file instanceof DownloadedFile
&& null !== $file->getOriginalFilename()
&& '' !== $file->getOriginalFilename()
&& $file->getOriginalFilename() !== null
&& $file->getOriginalFilename() !== ''
) {
$fileName = $file->getOriginalFilename();
} else {
Expand All @@ -272,6 +292,9 @@ protected function getFileName(): string
/**
* Create a Document from an external URL.
*
* @param string $downloadUrl
*
* @return DocumentInterface|null
* @throws FilesystemException
*/
public function getDocumentFromUrl(string $downloadUrl): ?DocumentInterface
Expand All @@ -280,7 +303,6 @@ public function getDocumentFromUrl(string $downloadUrl): ?DocumentInterface
if (null !== $downloadedFile) {
return $this->setFile($downloadedFile)->getDocument();
}

return null;
}
}
Loading

0 comments on commit 58f2d47

Please sign in to comment.