Skip to content

Commit

Permalink
Merge pull request #119 from chives/php8
Browse files Browse the repository at this point in the history
Ripped out old dependencies and allow php 8
  • Loading branch information
szymach authored Feb 8, 2021
2 parents 14116a3 + 7402cbf commit 4836487
Show file tree
Hide file tree
Showing 52 changed files with 839 additions and 1,244 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/vendor
/tests/temp
composer.lock
composer.phar
autoload.php
.phpcs-cache
.phpunit.result.cache
13 changes: 0 additions & 13 deletions .scrutinizer.yml

This file was deleted.

8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ matrix:
- php: 7.4
env:
- SYMFONY_DEPRECATIONS_HELPER=weak
- php: 8.0
env:
- SYMFONY_DEPRECATIONS_HELPER=weak

before_script:
- composer validate
- composer update $COMPOSER_FLAGS

script: vendor/bin/phpunit
script:
- vendor/bin/phpcs
- vendor/bin/phpstan analyze -c phpstan.neon
- vendor/bin/phpunit
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
}
],
"require": {
"php": ">=7.1",
"doctrine/common": "^2.5",
"php": "^7.1|^8.0",
"doctrine/common": "^2.9|^3.0",
"doctrine/orm": "^2.5",
"symfony/property-access": "^2.3|^3.0|^4.0",
"symfony/yaml": "^2.2|^3.0|^4.0",
"doctrine/persistence": "^1.3|^2.0",
"symfony/property-access": "^3.0|^4.0|^5.0",
"symfony/yaml": "^3.0|^4.0|^5.0",
"knplabs/gaufrette": "~0.1,>=0.1.4"
},
"require-dev": {
"doctrine/dbal": "^2.5",
"ext-dom": "*",
"ext-intl": "*",
"ext-sqlite3": "*",
"phpunit/phpunit": "^7.5",
"ext-pdo_sqlite": "*",
"ext-simplexml": "*",
"doctrine/dbal": "^2.5",
"phpstan/phpstan": "^0.12.26",
"phpunit/phpunit": "^7.5|^8.0",
"squizlabs/php_codesniffer": "^3.4",
"symfony/phpunit-bridge": "^5.0"
},
"autoload": {
Expand All @@ -45,6 +50,7 @@
"extra": {
"branch-alias": {
"dev-master": "3.0-dev",
"2.1": "2.1-dev",
"2.0": "2.0-dev",
"1.2": "1.2-dev",
"1.1": "1.1-dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace FSi\DoctrineExtensions\Mapping\Driver;

use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use FSi\DoctrineExtensions\Mapping\Driver\DriverInterface;
use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;
Expand Down Expand Up @@ -50,7 +50,10 @@ public function loadClassMetadata(ClassMetadataInterface $metadata): void
return;
}

$this->loadExtendedClassMetadata($this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()), $metadata);
$this->loadExtendedClassMetadata(
$this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()),
$metadata
);
}

public function setAnnotationReader(Reader $reader): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace FSi\DoctrineExtensions\Mapping\Driver;

use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\Driver\FileLocator;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\Mapping\Driver\FileLocator;
use FSi\DoctrineExtensions\Mapping\Driver\DriverInterface;
use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;
Expand Down Expand Up @@ -54,7 +54,10 @@ public function loadClassMetadata(ClassMetadataInterface $metadata): void
return;
}

$this->loadExtendedClassMetadata($this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()), $metadata);
$this->loadExtendedClassMetadata(
$this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()),
$metadata
);
}

public function setFileLocator(FileLocator $locator): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private function validateFile(DOMDocument $dom): bool
{
// Schemas for validation.
$schemaLocations = [
'http://fsi.pl/schemas/orm/doctrine-extensions-mapping' => realpath(__DIR__ . '/../../../../../doctrine-extensions-mapping.xsd'),
'http://fsi.pl/schemas/orm/doctrine-extensions-mapping'
=> dirname(__DIR__, 5) . '/doctrine-extensions-mapping.xsd',
'http://doctrine-project.org/schemas/orm/doctrine-mapping' => $this->getDoctrineSchemePath(),
];

Expand All @@ -89,7 +90,7 @@ private function validateFile(DOMDocument $dom): bool
}

$domNodeList = $dom->getElementsByTagNameNS($xmlns->nodeValue, '*');
for ($i = $domNodeList->length; --$i >= 0; ) {
for ($i = $domNodeList->length; --$i >= 0;) {
$element = $domNodeList->item($i);
$element->parentNode->removeChild($element);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/FSi/DoctrineExtensions/Mapping/Driver/DriverChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace FSi\DoctrineExtensions\Mapping\Driver;

use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace FSi\DoctrineExtensions\Mapping\Driver;

use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;

interface DriverInterface
Expand Down
12 changes: 7 additions & 5 deletions lib/FSi/DoctrineExtensions/Mapping/ExtendedMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use FSi\DoctrineExtensions\Mapping\Driver\AbstractAnnotationDriver;
use FSi\DoctrineExtensions\Mapping\Driver\AbstractFileDriver;
use FSi\DoctrineExtensions\Mapping\Driver\DriverChain;
use FSi\DoctrineExtensions\Mapping\Driver\DriverInterface;
use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException;
use FSi\DoctrineExtensions\Metadata\ClassMetadata;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;
use ReflectionClass;
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
use function class_exists;

final class ExtendedMetadataFactory
{
Expand Down Expand Up @@ -104,7 +104,9 @@ public function __construct(
'\\'
);
if (!class_exists($metadataClassName)) {
throw new RuntimeException(sprintf('Metadata class "%s" does not exist!'));
throw new RuntimeException(
sprintf('Metadata class "%s" does not exist!', class_exists($metadataClassName))
);
}

$metadataClassReflection = new ReflectionClass($metadataClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\Mapping\ClassMetadata;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;
use RuntimeException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace FSi\DoctrineExtensions\Translatable;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use FSi\DoctrineExtensions\Translatable\Mapping\TranslationAssociationMetadata;
use FSi\DoctrineExtensions\Translatable\Model\TranslatableRepositoryInterface;
use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata as TranslatableClassMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,8 @@ public function createTranslatableQueryBuilder(
$translatableProperties = $this->getExtendedMetadata()->getTranslatableProperties();
foreach (array_keys($translatableProperties) as $translationAssociation) {
$join = sprintf('%s.%s', $alias, $translationAssociation);
$qb->joinAndSelectCurrentTranslations(
$join, Expr\Join::LEFT_JOIN,
$translationAlias,
'locale'
);
$qb->joinAndSelectDefaultTranslations(
$join, Expr\Join::LEFT_JOIN,
$defaultTranslationAlias,
'deflocale'
);
$qb->joinAndSelectCurrentTranslations($join, Expr\Join::LEFT_JOIN, $translationAlias, 'locale');
$qb->joinAndSelectDefaultTranslations($join, Expr\Join::LEFT_JOIN, $defaultTranslationAlias, 'deflocale');
}

return $qb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
use FSi\DoctrineExtensions\Translatable\Exception\AnnotationException;
use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata;
use RuntimeException;
use FSi\DoctrineExtensions\Translatable\Mapping\Annotation\Translatable;
use FSi\DoctrineExtensions\Translatable\Mapping\Annotation\Locale;

class Annotation extends AbstractAnnotationDriver
{
public const TRANSLATABLE = 'FSi\\DoctrineExtensions\\Translatable\\Mapping\\Annotation\\Translatable';
public const LOCALE = 'FSi\\DoctrineExtensions\\Translatable\\Mapping\\Annotation\\Locale';
public const TRANSLATABLE = Translatable::class;
public const LOCALE = Locale::class;

/**
* @param ClassMetadataInfo $baseClassMetadata
Expand Down Expand Up @@ -52,7 +54,8 @@ protected function loadExtendedClassMetadata(
continue;
}

$translatableAnnotation = $this->getAnnotationReader()->getPropertyAnnotation($property, self::TRANSLATABLE);
$translatableAnnotation = $this->getAnnotationReader()
->getPropertyAnnotation($property, self::TRANSLATABLE);
if ($translatableAnnotation) {
if (!isset($translatableAnnotation->mappedBy)) {
throw new AnnotationException(
Expand Down
32 changes: 14 additions & 18 deletions lib/FSi/DoctrineExtensions/Translatable/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata as TranslatableClassMetadata;
use FSi\DoctrineExtensions\Translatable\Exception\RuntimeException;
use FSi\DoctrineExtensions\Translatable\TranslatableListener;
use function sprintf;

class QueryBuilder extends BaseQueryBuilder
{
Expand Down Expand Up @@ -532,6 +533,8 @@ private function getJoinedTranslationsAlias(string $join, string $locale): ?stri
if (isset($this->translationsAliases[$join][$locale])) {
return $this->translationsAliases[$join][$locale];
}

return null;
}

private function getTranslationField(string $alias, string $property): string
Expand All @@ -546,7 +549,11 @@ private function getTranslationField(string $alias, string $property): string
}
}

$this->throwUnknownTranslatablePropertyException($alias, $property);
throw new RuntimeException(sprintf(
'Unknown translatable property "%s" in class "%s"',
$property,
$this->getClassByAlias($alias)
));
}

private function getTranslationAssociation(string $alias, string $property): string
Expand All @@ -561,7 +568,11 @@ private function getTranslationAssociation(string $alias, string $property): str
}
}

$this->throwUnknownTranslatablePropertyException($alias, $property);
throw new RuntimeException(sprintf(
'Unknown translatable property "%s" in class "%s"',
$property,
$this->getClassByAlias($alias)
));
}

private function joinCurrentTranslationsOnce(
Expand Down Expand Up @@ -623,21 +634,6 @@ private function joinAndSelectTranslationsOnce(
}
}

/**
* @param string $alias
* @param string $property
* @return void
* @throws RuntimeException
*/
private function throwUnknownTranslatablePropertyException(string $alias, string $property): void
{
throw new RuntimeException(sprintf(
'Unknown translatable property "%s" in class "%s"',
$property,
$this->getClassByAlias($alias)
));
}

private function hasDefaultLocaleDifferentThanCurrentLocale(?string $locale): bool
{
$defaultLocale = $this->getTranslatableListener()->getDefaultLocale();
Expand Down Expand Up @@ -751,7 +747,7 @@ private function addTranslatableWhereOnCollection(
$this->andWhere($collectionExpr);
} elseif (is_array($value)) {
if ($this->isTranslatableProperty($alias, $field)) {
$fieldExpr = $this->expr()->in('%s', $parameter);
$fieldExpr = (string) $this->expr()->in('%s', $parameter);
$collectionExpr = $this->getTranslatableCollectionExpr($alias, $field, $fieldExpr, true, $locale);
$this->andWhere($collectionExpr);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace FSi\DoctrineExtensions\Translatable;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\Persistence\Mapping\ClassMetadata;
use FSi\DoctrineExtensions\Mapping\MappedEventSubscriber;
use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface;
use FSi\DoctrineExtensions\Translatable\Exception;
Expand Down
1 change: 0 additions & 1 deletion lib/FSi/DoctrineExtensions/Uploadable/Keymaker/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ public function createKey(
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
namespace FSi\DoctrineExtensions\Uploadable\Keymaker;

use Doctrine\Common\Util\ClassUtils;
use function preg_replace;
use function transliterator_transliterate;
use function trim;

class TransliterateEntity implements KeymakerInterface
{
Expand Down Expand Up @@ -52,9 +55,6 @@ private function cleanFileName(string $originalName): string
$originalName
);

return trim(preg_replace(
'/[-\s]+/', '-',
preg_replace('/[^\da-z.\-\s]+/', '', $transliteratedName)
));
return trim(preg_replace('/[-\s]+/', '-', preg_replace('/[^\da-z.\-\s]+/', '', $transliteratedName)));
}
}
Loading

0 comments on commit 4836487

Please sign in to comment.