Skip to content

Commit

Permalink
Travis: phpstan & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed May 27, 2017
1 parent 943549c commit 497e6f9
Show file tree
Hide file tree
Showing 37 changed files with 332 additions and 270 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ matrix:
include:
- php: 7.1
env: COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- php: 7.1
env: COMPOSER_EXTRA_ARGS="--prefer-stable" PHPSTAN=1
exclude:
- php: 7.1
env: COMPOSER_EXTRA_ARGS="--prefer-stable"
Expand All @@ -37,6 +39,7 @@ matrix:
env: COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"

install:
- if [ "$PHPSTAN" = "1" ]; then composer require --dev --no-update phpstan/phpstan-shim:^0.7; fi
- travis_retry composer update --no-interaction --no-suggest --no-progress --prefer-dist $COMPOSER_EXTRA_ARGS
- travis_retry composer create-project --no-interaction jakub-onderka/php-parallel-lint /tmp/php-parallel-lint
- travis_retry composer create-project --no-interaction kdyby/code-checker /tmp/code-checker
Expand All @@ -46,6 +49,7 @@ script:
- vendor/bin/tester $COVERAGE -s -p ${TESTER_RUNTIME:-php} -c ./tests/php.ini-unix ./tests/KdybyTests/
- php /tmp/php-parallel-lint/parallel-lint.php -e php,phpt --exclude vendor .
- php /tmp/code-checker/src/code-checker.php --short-arrays
- if [ "$PHPSTAN" = "1" ]; then php vendor/phpstan/phpstan-shim/phpstan.phar analyse --ansi --no-progress -l7 -c phpstan.neon src tests/KdybyTests; fi

after_script:
- if [ "$COVERAGE" != "" ]; then php /tmp/coveralls.phar --verbose --config tests/.coveralls.yml || true; fi
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"autoload-dev": {
"classmap": [
"tests/KdybyTests/Doctrine"
"tests/KdybyTests"
]
},
"extra": {
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
- '#Constant TEMP_DIR not found#'
- '#Constant TEST_DIR not found#'
- '#Parameter \#1 \$maxResults of method [^\s]+::setMaxResults\(\) expects int, (int\|)?null given#'
- '#Parameter \#1 \$firstResult of method [^\s]+::setFirstResult\(\) expects int, (int\|)?null given#'
- '#Parameter \#3 \$type of method Doctrine\\ORM\\QueryBuilder::setParameter\(\) expects string\|null, int given.#'
- '#Parameter \#1 \$reader of parent constructor expects Doctrine\\Common\\Annotations\\AnnotationReader, Doctrine\\Common\\Annotations\\AnnotationReader\|Doctrine\\Common\\Annotations\\Reader given.#'
- '#Kdyby\\Doctrine\\EmptyResultSet::__construct\(\) does not call parent constructor from Kdyby\\Doctrine\\ResultSet.#'
- '#Call to an undefined method Serializable::__sleep\(\).#'
- '#Call to an undefined method Serializable::__wakeup\(\).#'
22 changes: 13 additions & 9 deletions src/Kdyby/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,17 @@ public function ping()
* @param array $params
* @param \Doctrine\DBAL\Configuration $config
* @param \Doctrine\Common\EventManager $eventManager
* @return Connection
* @return \Kdyby\Doctrine\Connection
*/
public static function create(array $params, Doctrine\DBAL\Configuration $config, EventManager $eventManager)
{
if (!isset($params['wrapperClass'])) {
$params['wrapperClass'] = get_called_class();
}

return Doctrine\DBAL\DriverManager::getConnection($params, $config, $eventManager);
/** @var \Kdyby\Doctrine\Connection $connection */
$connection = Doctrine\DBAL\DriverManager::getConnection($params, $config, $eventManager);
return $connection;
}


Expand All @@ -373,7 +375,7 @@ public static function create(array $params, Doctrine\DBAL\Configuration $config
* @param \Exception|\Throwable $e
* @param string $query
* @param array $params
* @return DBALException
* @return \Kdyby\Doctrine\DBALException|\Exception|\Throwable
*/
public function resolveException($e, $query = NULL, $params = [])
{
Expand All @@ -396,12 +398,14 @@ public function resolveException($e, $query = NULL, $params = [])
$columns = [];

try {
if (preg_match('~Duplicate entry .*? for key \'([^\']+)\'~', $info[2], $m)
&& ($table = self::resolveExceptionTable($e))
&& ($indexes = $this->getSchemaManager()->listTableIndexes($table))
&& isset($indexes[$m[1]])
) {
$columns[$m[1]] = $indexes[$m[1]]->getColumns();
if (preg_match('~Duplicate entry .*? for key \'([^\']+)\'~', $info[2], $m)) {
$table = self::resolveExceptionTable($e);
if ($table !== NULL) {
$indexes = $this->getSchemaManager()->listTableIndexes($table);
if (array_key_exists($m[1], $indexes)) {
$columns[$m[1]] = $indexes[$m[1]]->getColumns();
}
}
}

} catch (\Exception $e) { }
Expand Down
10 changes: 7 additions & 3 deletions src/Kdyby/Doctrine/Console/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ public static function setApplicationEntityManager(ContainerHelper $containerHel
/** @var \Kdyby\Doctrine\EntityManager $em */
$em = $containerHelper->getByType(\Kdyby\Doctrine\Registry::class)->getManager($emName);
$helperSet = $containerHelper->getHelperSet();
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
if ($helperSet !== NULL) {
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
}
}

public static function setApplicationConnection(ContainerHelper $containerHelper, $connName)
{
/** @var \Kdyby\Doctrine\EntityManager $db */
$connection = $containerHelper->getByType(\Kdyby\Doctrine\Registry::class)->getConnection($connName);
$helperSet = $containerHelper->getHelperSet();
$helperSet->set(new ConnectionHelper($connection), 'db');
if ($helperSet !== NULL) {
$helperSet->set(new ConnectionHelper($connection), 'db');
}
}

}
8 changes: 5 additions & 3 deletions src/Kdyby/Doctrine/DI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public function loadConfiguration()
throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file.");
}

/** @var mixed[] $emConfig */
$emConfig = Nette\DI\Config\Helpers::merge($emConfig, $defaults);
$this->processEntityManager($name, $emConfig);
}
Expand Down Expand Up @@ -675,7 +676,7 @@ protected function processRepositories()
}

$serviceMap = array_fill_keys(array_keys($this->configuredManagers), []);
foreach ($builder->findByType(Doctrine\ORM\EntityRepository::class, FALSE) as $originalServiceName => $originalDef) {
foreach ($builder->findByType(Doctrine\ORM\EntityRepository::class) as $originalServiceName => $originalDef) {
if (is_string($originalDef)) {
$originalServiceName = $originalDef;
$originalDef = $builder->getDefinition($originalServiceName);
Expand All @@ -685,7 +686,8 @@ protected function processRepositories()
continue; // ignore
}

$factory = $originalDef->getFactory() ? $originalDef->getFactory()->getEntity() : $originalDef->getClass();
$originalDefFactory = $originalDef->getFactory();
$factory = ($originalDefFactory !== NULL) ? $originalDefFactory->getEntity() : $originalDef->getClass();
if (stripos($factory, '::getRepository') !== FALSE) {
continue; // ignore
}
Expand Down Expand Up @@ -779,7 +781,7 @@ public function afterCompile(Code\ClassType $class)
foreach ($this->proxyAutoloaders as $namespace => $dir) {
$originalInitialize = $init->getBody();
$init->setBody('?::create(?, ?)->register();', [new Code\PhpLiteral(Kdyby\Doctrine\Proxy\ProxyAutoloader::class), $dir, $namespace]);
$init->addBody($originalInitialize);
$init->addBody((string) $originalInitialize);
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/Kdyby/Doctrine/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ protected function processQuery(array $query)

/**
* @param \Exception|\Throwable $e
* @return void|array
* @return array|NULL
*/
public function renderQueryException($e)
{
Expand Down Expand Up @@ -357,7 +357,7 @@ public function renderQueryException($e)
/**
* @param \Exception|\Throwable $e
* @param \Nette\DI\Container $dic
* @return array
* @return array|NULL
*/
public static function renderException($e, Nette\DI\Container $dic)
{
Expand Down Expand Up @@ -408,7 +408,7 @@ public static function renderException($e, Nette\DI\Container $dic)
];
}

} elseif ($e instanceof Kdyby\Doctrine\DBALException && $e->query) {
} elseif ($e instanceof Kdyby\Doctrine\DBALException && $e->query !== NULL) {
return [
'tab' => 'SQL',
'panel' => self::highlightQuery(static::formatQuery($e->query, $e->params, [])),
Expand Down Expand Up @@ -467,8 +467,7 @@ public static function renderException($e, Nette\DI\Container $dic)
* @param array|Doctrine\Common\Collections\ArrayCollection $params
* @param array $types
* @param string $source
*
* @return array
* @return string
*/
protected function dumpQuery($query, $params, array $types = [], $source = NULL)
{
Expand Down Expand Up @@ -560,7 +559,7 @@ public static function highlightQuery($sql)
*/
public static function formatQuery($query, $params, array $types = [], AbstractPlatform $platform = NULL)
{
if (!$platform) {
if ($platform === NULL) {
$platform = new Doctrine\DBAL\Platforms\MySqlPlatform();
}

Expand Down Expand Up @@ -660,7 +659,8 @@ public static function highlightAnnotationLine(AnnotationException $e)
$refl = $refl->getProperty($context['method']);
}

if (($errorLine = self::calculateErrorLine($refl, $e, $line)) === NULL) {
$errorLine = self::calculateErrorLine($refl, $e, $line);
if ($errorLine === NULL) {
return FALSE;
}

Expand All @@ -675,7 +675,7 @@ public static function highlightAnnotationLine(AnnotationException $e)
* @param \Reflector|\Nette\Reflection\ClassType|\Nette\Reflection\Method|\Nette\Reflection\Property $refl
* @param \Exception|\Throwable $e
* @param int|NULL $startLine
* @return int|string|NULL
* @return int|NULL
*/
public static function calculateErrorLine(\Reflector $refl, $e, $startLine = NULL)
{
Expand Down Expand Up @@ -712,12 +712,13 @@ public static function calculateErrorLine(\Reflector $refl, $e, $startLine = NUL
/**
* @param \Reflector|\Nette\Reflection\ClassType|\Nette\Reflection\Method $refl
* @param int $symbolPos
*
* @return int
*/
protected static function calculateAffectedLine(\Reflector $refl, $symbolPos)
{
$doc = $refl->getDocComment();
/** @var int|NULL $atPos */
$atPos = NULL;
$cleanedDoc = self::cleanedPhpDoc($refl, $atPos);
$beforeCleanLines = count(Strings::split(substr($doc, 0, $atPos), '~[\n\r]+~'));
$parsedDoc = substr($cleanedDoc, 0, $symbolPos + 1);
Expand Down Expand Up @@ -760,8 +761,7 @@ private static function findRenamed(\Reflector $refl, $annotation)

/**
* @param \Nette\Reflection\ClassType|\Nette\Reflection\Method|\Reflector $refl
* @param null $atPos
*
* @param int|null $atPos
* @return string
*/
private static function cleanedPhpDoc(\Reflector $refl, &$atPos = NULL)
Expand All @@ -775,7 +775,7 @@ private static function cleanedPhpDoc(\Reflector $refl, &$atPos = NULL)
* Returns link to editor.
* @author David Grudl
* @param string $file
* @param string $line
* @param string|int $line
* @param string $text
* @return Nette\Utils\Html
*/
Expand All @@ -784,11 +784,11 @@ private static function editorLink($file, $line, $text = NULL)
if (Debugger::$editor && is_file($file) && $text !== NULL) {
return Nette\Utils\Html::el('a')
->href(strtr(Debugger::$editor, ['%file' => rawurlencode($file), '%line' => $line]))
->title("$file:$line")
->setAttribute('title', "$file:$line")
->setHtml($text);

} else {
return Helpers::editorLink($file, $line);
return Nette\Utils\Html::el()->setHtml(Helpers::editorLink($file, $line));
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/Kdyby/Doctrine/Dql/InlineParamsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class InlineParamsBuilder extends Kdyby\Doctrine\QueryBuilder
*/
public function join($join, $alias, $conditionType = NULL, $condition = NULL, $indexBy = NULL)
{
return call_user_func_array([$this, 'innerJoin'], func_get_args());
call_user_func_array([$this, 'innerJoin'], func_get_args());
return $this;
}


Expand All @@ -48,7 +49,8 @@ public function innerJoin($join, $alias, $conditionType = NULL, $condition = NUL
}
}

return parent::innerJoin($join, $alias, $conditionType, $condition, $indexBy);
parent::innerJoin($join, $alias, $conditionType, $condition, $indexBy);
return $this;
}


Expand All @@ -68,7 +70,8 @@ public function leftJoin($join, $alias, $conditionType = NULL, $condition = NULL
}
}

return parent::leftJoin($join, $alias, $conditionType, $condition, $indexBy);
parent::leftJoin($join, $alias, $conditionType, $condition, $indexBy);
return $this;
}


Expand All @@ -79,7 +82,8 @@ public function leftJoin($join, $alias, $conditionType = NULL, $condition = NULL
*/
public function where($predicates)
{
return call_user_func_array('parent::where', Helpers::separateParameters($this, func_get_args()));
call_user_func_array('parent::where', Helpers::separateParameters($this, func_get_args()));
return $this;
}


Expand All @@ -90,7 +94,8 @@ public function where($predicates)
*/
public function andWhere()
{
return call_user_func_array('parent::andWhere', Helpers::separateParameters($this, func_get_args()));
call_user_func_array('parent::andWhere', Helpers::separateParameters($this, func_get_args()));
return $this;
}


Expand All @@ -101,7 +106,8 @@ public function andWhere()
*/
public function orWhere()
{
return call_user_func_array('parent::orWhere', Helpers::separateParameters($this, func_get_args()));
call_user_func_array('parent::orWhere', Helpers::separateParameters($this, func_get_args()));
return $this;
}

}
11 changes: 4 additions & 7 deletions src/Kdyby/Doctrine/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function createQueryBuilder($alias = NULL, $indexBy = NULL)
throw new NotSupportedException('Use EntityRepository for $alias and $indexBy arguments to work.');
}

if (($config = $this->getConfiguration()) instanceof Configuration) {
$config = $this->getConfiguration();
if ($config instanceof Configuration) {
$class = $config->getQueryBuilderClassName();
return new $class($this);
}
Expand All @@ -91,8 +92,7 @@ public function createQueryBuilder($alias = NULL, $indexBy = NULL)


/**
* {@inheritdoc}
* @param string|array $entity
* @param string|array|null $entityName if given, only entities of this type will get detached
* @return EntityManager
*/
public function clear($entityName = null)
Expand All @@ -107,7 +107,6 @@ public function clear($entityName = null)


/**
* {@inheritdoc}
* @param object|array $entity
* @return EntityManager
*/
Expand All @@ -123,7 +122,6 @@ public function remove($entity)


/**
* {@inheritdoc}
* @param object|array $entity
* @return EntityManager
*/
Expand All @@ -139,8 +137,7 @@ public function persist($entity)


/**
* {@inheritdoc}
* @param object|array $entity
* @param object|array|NULL $entity
* @return EntityManager
*/
public function flush($entity = null)
Expand Down
Loading

0 comments on commit 497e6f9

Please sign in to comment.