1
0
mirror of synced 2025-02-10 17:29:27 +03:00

Merge pull request #6535 from Majkl578/phpstan

[master] PHPStan integration - levels 0 + 1
This commit is contained in:
Luís Cobucci 2017-07-07 10:36:08 +02:00 committed by GitHub
commit c32ba8f5d1
8 changed files with 51 additions and 31 deletions

View File

@ -14,13 +14,16 @@ env:
before_script: before_script:
- if [[ $TRAVIS_PHP_VERSION = '7.1' && $DB = 'sqlite' && "$DEPENDENCIES" != "low" ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - if [[ $TRAVIS_PHP_VERSION = '7.1' && $DB = 'sqlite' && "$DEPENDENCIES" != "low" ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi
- if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini; fi - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini; fi
- if [[ $PHPSTAN = 1 ]]; then echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
- composer self-update - composer self-update
- composer install --prefer-source - composer install --prefer-source
- if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi;
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi;
- if [[ $PHPSTAN = 1 ]]; then composer require --dev --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0; fi
- if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi;
script: script:
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib; fi
- ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS
- ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional
@ -39,6 +42,10 @@ matrix:
env: env:
- DB=sqlite - DB=sqlite
- DEPENDENCIES='low' - DEPENDENCIES='low'
- php: 7.1
env:
- DB=pgsql
- PHPSTAN=1
allow_failures: allow_failures:
- php: nightly - php: nightly

View File

@ -548,28 +548,28 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
$hasCache = ($persister instanceof CachedPersister); $hasCache = ($persister instanceof CachedPersister);
$key = null; $key = null;
if ($hasCache) { if ( ! $hasCache) {
$ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); return $this->persister->loadManyToManyCollection($assoc, $sourceEntity, $coll);
$key = $this->buildCollectionCacheKey($assoc, $ownerId); }
$list = $persister->loadCollectionCache($coll, $key);
if ($list !== null) { $ownerId = $this->uow->getEntityIdentifier($coll->getOwner());
if ($this->cacheLogger) { $key = $this->buildCollectionCacheKey($assoc, $ownerId);
$this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key); $list = $persister->loadCollectionCache($coll, $key);
}
return $list; if ($list !== null) {
if ($this->cacheLogger) {
$this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key);
} }
return $list;
} }
$list = $this->persister->loadManyToManyCollection($assoc, $sourceEntity, $coll); $list = $this->persister->loadManyToManyCollection($assoc, $sourceEntity, $coll);
if ($hasCache) { $persister->storeCollectionCache($key, $list);
$persister->storeCollectionCache($key, $list);
if ($this->cacheLogger) { if ($this->cacheLogger) {
$this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key); $this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key);
}
} }
return $list; return $list;
@ -583,28 +583,28 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
$persister = $this->uow->getCollectionPersister($assoc); $persister = $this->uow->getCollectionPersister($assoc);
$hasCache = ($persister instanceof CachedPersister); $hasCache = ($persister instanceof CachedPersister);
if ($hasCache) { if ( ! $hasCache) {
$ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); return $this->persister->loadOneToManyCollection($assoc, $sourceEntity, $coll);
$key = $this->buildCollectionCacheKey($assoc, $ownerId); }
$list = $persister->loadCollectionCache($coll, $key);
if ($list !== null) { $ownerId = $this->uow->getEntityIdentifier($coll->getOwner());
if ($this->cacheLogger) { $key = $this->buildCollectionCacheKey($assoc, $ownerId);
$this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key); $list = $persister->loadCollectionCache($coll, $key);
}
return $list; if ($list !== null) {
if ($this->cacheLogger) {
$this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key);
} }
return $list;
} }
$list = $this->persister->loadOneToManyCollection($assoc, $sourceEntity, $coll); $list = $this->persister->loadOneToManyCollection($assoc, $sourceEntity, $coll);
if ($hasCache) { $persister->storeCollectionCache($key, $list);
$persister->storeCollectionCache($key, $list);
if ($this->cacheLogger) { if ($this->cacheLogger) {
$this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key); $this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key);
}
} }
return $list; return $list;

View File

@ -514,10 +514,11 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
public function offsetSet($offset, $value) public function offsetSet($offset, $value)
{ {
if ( ! isset($offset)) { if ( ! isset($offset)) {
return $this->add($value); $this->add($value);
return;
} }
return $this->set($offset, $value); $this->set($offset, $value);
} }
/** /**

View File

@ -542,6 +542,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
$identifier1 = $this->uow->getEntityIdentifier($collection->getOwner()); $identifier1 = $this->uow->getEntityIdentifier($collection->getOwner());
$identifier2 = $this->uow->getEntityIdentifier($element); $identifier2 = $this->uow->getEntityIdentifier($element);
$class1 = $class2 = null;
if ($isComposite) { if ($isComposite) {
$class1 = $this->em->getClassMetadata(get_class($collection->getOwner())); $class1 = $this->em->getClassMetadata(get_class($collection->getOwner()));
$class2 = $collection->getTypeClass(); $class2 = $collection->getTypeClass();

View File

@ -451,7 +451,7 @@ class ResultSetMapping
/** /**
* @param string $alias * @param string $alias
* *
* @return AssociationMapping * @return string
*/ */
public function getRelation($alias) public function getRelation($alias)
{ {

View File

@ -102,6 +102,7 @@ class PhpExporter extends AbstractExporter
$cascade = ['all']; $cascade = ['all'];
} }
$method = null;
$associationMappingArray = [ $associationMappingArray = [
'fieldName' => $associationMapping['fieldName'], 'fieldName' => $associationMapping['fieldName'],
'targetEntity' => $associationMapping['targetEntity'], 'targetEntity' => $associationMapping['targetEntity'],
@ -129,6 +130,7 @@ class PhpExporter extends AbstractExporter
'orphanRemoval', 'orphanRemoval',
'orderBy', 'orderBy',
]; ];
$oneToManyMappingArray = [];
foreach ($potentialAssociationMappingIndexes as $index) { foreach ($potentialAssociationMappingIndexes as $index) {
if (isset($associationMapping[$index])) { if (isset($associationMapping[$index])) {
$oneToManyMappingArray[$index] = $associationMapping[$index]; $oneToManyMappingArray[$index] = $associationMapping[$index];
@ -142,6 +144,7 @@ class PhpExporter extends AbstractExporter
'joinTable', 'joinTable',
'orderBy', 'orderBy',
]; ];
$manyToManyMappingArray = [];
foreach ($potentialAssociationMappingIndexes as $index) { foreach ($potentialAssociationMappingIndexes as $index) {
if (isset($associationMapping[$index])) { if (isset($associationMapping[$index])) {
$manyToManyMappingArray[$index] = $associationMapping[$index]; $manyToManyMappingArray[$index] = $associationMapping[$index];

View File

@ -240,6 +240,7 @@ class XmlExporter extends AbstractExporter
}); });
foreach ($metadata->associationMappings as $associationMapping) { foreach ($metadata->associationMappings as $associationMapping) {
$associationMappingXml = null;
if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) { if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) {
$associationMappingXml = $root->addChild('one-to-one'); $associationMappingXml = $root->addChild('one-to-one');
} elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) { } elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) {

7
phpstan.neon Normal file
View File

@ -0,0 +1,7 @@
parameters:
earlyTerminatingMethodCalls:
Doctrine\ORM\Query\Parser:
- syntaxError
ignoreErrors:
# Memcache does not exist on PHP 7
- '#Instantiated class Memcache not found#'