Skip to content

Commit

Permalink
PSR-4 Autoloading
Browse files Browse the repository at this point in the history
- Exceptions were moved in separated files
- Added aliases for exceptions
- Composer require PHP at ^7.1
  • Loading branch information
jelen07 committed Mar 21, 2019
1 parent e894e0e commit 98ade15
Show file tree
Hide file tree
Showing 32 changed files with 357 additions and 319 deletions.
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ addons:
- mysql

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

env:
- # dev
Expand All @@ -27,31 +26,26 @@ env:
matrix:
fast_finish: true
include:
- php: 7.2
- php: 7.3
env: COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- php: 7.2
- php: 7.3
env: COMPOSER_EXTRA_ARGS="--prefer-stable" PHPSTAN=1
- php: 7.3
env: COMPOSER_EXTRA_ARGS="--prefer-stable" CODING_STANDARD=1
exclude:
- php: 7.2
- php: 7.3
env: COMPOSER_EXTRA_ARGS="--prefer-stable"
allow_failures:
- env:
- php: 7.2
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.9; 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
- if [ "$COVERAGE" != "" ]; then travis_retry wget -O /tmp/coveralls.phar https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi

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 -v; fi
- if [ "$PHPSTAN" = "1" ]; then php vendor/phpstan/phpstan-shim/phpstan.phar analyse --ansi --no-progress -l7 -c phpstan.neon src tests/KdybyTests; fi
- vendor/bin/parallel-lint -e php,phpt --exclude vendor .
- if [ "$PHPSTAN" = "1" ]; then php vendor/phpstan/phpstan-shim/phpstan.phar -v; fi

after_script:
- if [ "$COVERAGE" != "" ]; then php /tmp/coveralls.phar --verbose --config tests/.coveralls.yml || true; fi
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"issues": "https://github.com/kdyby/doctrine/issues"
},
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.1",
"doctrine/orm": "~2.5",
"doctrine/dbal": "~2.5",
"kdyby/console": "^2.7.1",
Expand All @@ -40,17 +40,17 @@
"nette/caching": "^2.5.3",
"nette/http": "^2.4.7@dev",
"tracy/tracy": "^2.4@dev",
"nette/tester": "^2.0"
"nette/tester": "^2.0",
"kdyby/coding-standard": "^1.0@dev",
"phpstan/phpstan-shim": "^0.11",
"jakub-onderka/php-parallel-lint": "^1.0"
},
"minimum-stability": "dev",
"autoload": {
"psr-0": {
"Kdyby\\Doctrine\\": "src/",
"Kdyby\\Persistence\\": "src/"
},
"classmap": [
"src/Kdyby/Doctrine/exceptions.php"
]
"psr-4": {
"Kdyby\\Doctrine\\": "src/Kdyby/Doctrine/",
"Kdyby\\Persistence\\": "src/Kdyby/Persistence/"
}
},
"autoload-dev": {
"classmap": [
Expand Down
5 changes: 4 additions & 1 deletion src/Kdyby/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Driver;
use Kdyby;
use Kdyby\Doctrine\Exception\DBALException;
use Kdyby\Doctrine\Exception\DuplicateEntryException;
use Kdyby\Doctrine\Exception\EmptyValueException;
use Nette;
use PDO;
use Tracy;
Expand Down Expand Up @@ -375,7 +378,7 @@ public static function create(array $params, Doctrine\DBAL\Configuration $config
* @param \Exception|\Throwable $e
* @param string $query
* @param array $params
* @return \Kdyby\Doctrine\DBALException|\Exception|\Throwable
* @return \Kdyby\Doctrine\Exception\DBALException|\Exception|\Throwable
*/
public function resolveException($e, $query = NULL, $params = [])
{
Expand Down
8 changes: 4 additions & 4 deletions src/Kdyby/Doctrine/DI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public function loadConfiguration()
}

if (empty($config)) {
throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file.");
throw new Kdyby\Doctrine\Exception\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file.");
}

foreach ($config as $name => $emConfig) {
if (!is_array($emConfig) || (empty($emConfig['dbname']) && empty($emConfig['driver']))) {
throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file.");
throw new Kdyby\Doctrine\Exception\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file.");
}

/** @var mixed[] $emConfig */
Expand Down Expand Up @@ -224,7 +224,7 @@ protected function loadConsole()
$cli->setClass($command);

} else {
throw new Kdyby\Doctrine\NotSupportedException;
throw new Kdyby\Doctrine\Exception\NotSupportedException;
}
}
}
Expand Down Expand Up @@ -845,7 +845,7 @@ private function addCollapsePathsToTracy(Method $init)
$blueScreen = \Tracy\Debugger::class . '::getBlueScreen()';
$commonDirname = dirname(Nette\Reflection\ClassType::from(Doctrine\Common\Version::class)->getFileName());

$init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(Nette\Reflection\ClassType::from(Kdyby\Doctrine\Exception::class)->getFileName())]);
$init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(Nette\Reflection\ClassType::from(Kdyby\Doctrine\Exception\IException::class)->getFileName())]);
$init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(dirname(dirname(dirname($commonDirname))))]); // this should be vendor/doctrine
foreach ($this->proxyAutoloaders as $dir) {
$init->addBody($blueScreen . '->collapsePaths[] = ?;', [$dir]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function renderEntityManagerException($e)
public function bindEntityManager(Doctrine\ORM\EntityManager $em)
{
if ($this->em !== NULL) {
throw new Kdyby\Doctrine\InvalidStateException(sprintf('%s is already bound to an entity manager.', __CLASS__));
throw new Kdyby\Doctrine\Exception\InvalidStateException(sprintf('%s is already bound to an entity manager.', __CLASS__));
}

$this->em = $em;
Expand Down
10 changes: 5 additions & 5 deletions src/Kdyby/Doctrine/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function renderQueryException($e)
'panel' => $this->dumpQuery($sql, $params, $types, $source),
];

} elseif ($e instanceof Kdyby\Doctrine\QueryException && $e->query !== NULL) {
} elseif ($e instanceof Kdyby\Doctrine\Exception\QueryException && $e->query !== NULL) {
if ($e->query instanceof Doctrine\ORM\Query) {
return [
'tab' => 'DQL',
Expand Down Expand Up @@ -409,7 +409,7 @@ public static function renderException($e, Nette\DI\Container $dic)
];
}

} elseif ($e instanceof Kdyby\Doctrine\DBALException && $e->query !== NULL) {
} elseif ($e instanceof Kdyby\Doctrine\Exception\DBALException && $e->query !== NULL) {
return [
'tab' => 'SQL',
'panel' => self::highlightQuery(static::formatQuery($e->query, $e->params, [])),
Expand Down Expand Up @@ -600,7 +600,7 @@ public static function formatQuery($query, $params, array $types = [], AbstractP
if (Nette\Utils\Validators::isList($params)) {
$parts = explode('?', $query);
if (count($params) > $parts) {
throw new Kdyby\Doctrine\InvalidStateException("Too mny parameters passed to query.");
throw new Kdyby\Doctrine\Exception\InvalidStateException("Too mny parameters passed to query.");
}

return implode('', Kdyby\Doctrine\Helpers::zipper($parts, $params));
Expand Down Expand Up @@ -803,7 +803,7 @@ private static function editorLink($file, $line, $text = NULL)
public function enableLogging()
{
if ($this->connection === NULL) {
throw new Kdyby\Doctrine\InvalidStateException("Doctrine Panel is not bound to connection.");
throw new Kdyby\Doctrine\Exception\InvalidStateException("Doctrine Panel is not bound to connection.");
}

$config = $this->connection->getConfiguration();
Expand All @@ -826,7 +826,7 @@ public function enableLogging()
public function bindConnection(Doctrine\DBAL\Connection $connection)
{
if ($this->connection !== NULL) {
throw new Kdyby\Doctrine\InvalidStateException("Doctrine Panel is already bound to connection.");
throw new Kdyby\Doctrine\Exception\InvalidStateException("Doctrine Panel is already bound to connection.");
}

$this->connection = $connection;
Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/Entities/SerializableMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Kdyby\Doctrine\Entities;

use Kdyby;
use Kdyby\Doctrine\StaticClassException;
use Kdyby\Doctrine\Exception\StaticClassException;
use Nette;
use Nette\Reflection\ClassType;
use Serializable;
Expand Down
2 changes: 2 additions & 0 deletions src/Kdyby/Doctrine/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Doctrine\ORM\Query;
use Kdyby;
use Kdyby\Doctrine\Diagnostics\EntityManagerUnitOfWorkSnapshotPanel;
use Kdyby\Doctrine\Exception\NotSupportedException;
use Kdyby\Doctrine\Exception\QueryException;
use Kdyby\Doctrine\QueryObject;
use Kdyby\Doctrine\Tools\NonLockingUniqueInserter;
use Kdyby\Persistence;
Expand Down
5 changes: 3 additions & 2 deletions src/Kdyby/Doctrine/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\NonUniqueResultException;
use Kdyby;
use Kdyby\Doctrine\Exception\QueryException;
use Kdyby\Persistence;
use Nette;

Expand Down Expand Up @@ -286,7 +287,7 @@ public function getReference($id)
/**
* @param \Exception $e
* @param \Kdyby\Persistence\Query $queryObject
* @return \Kdyby\Doctrine\QueryException
* @return \Kdyby\Doctrine\Exception\QueryException
*/
private function handleQueryException(\Exception $e, Persistence\Query $queryObject)
{
Expand All @@ -301,7 +302,7 @@ private function handleQueryException(\Exception $e, Persistence\Query $queryObj
* @param \Exception $e
* @param \Doctrine\ORM\Query $query
* @param string $message
* @return \Exception|\Kdyby\Doctrine\QueryException
* @return \Exception|\Kdyby\Doctrine\Exception\QueryException
*/
private function handleException(\Exception $e, Doctrine\ORM\Query $query = NULL, $message = NULL)
{
Expand Down
57 changes: 57 additions & 0 deletions src/Kdyby/Doctrine/Exception/DBALException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Kdyby\Doctrine\Exception;
use Doctrine;

/**
* @author Filip Procházka <filip@prochazka.su>
* @deprecated
*/
class DBALException extends \RuntimeException implements IException
{

/**
* @var string|NULL
*/
public $query;

/**
* @var array
*/
public $params = [];

/**
* @var \Doctrine\DBAL\Connection|NULL
*/
public $connection;


/**
* @param \Exception|\Throwable $previous
* @param string|NULL $query
* @param array $params
* @param \Doctrine\DBAL\Connection|NULL $connection
* @param string|NULL $message
*/
public function __construct($previous, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL, $message = NULL)
{
parent::__construct($message ?: $previous->getMessage(), $previous->getCode(), $previous);
$this->query = $query;
$this->params = $params;
$this->connection = $connection;
}


/**
* This is just a paranoia, hopes no one actually serializes exceptions.
*
* @return array
*/
public function __sleep()
{
return ['message', 'code', 'file', 'line', 'errorInfo', 'query', 'params'];
}

}

class_alias(DBALException::class, 'Kdyby\Doctrine\DBALException');
45 changes: 45 additions & 0 deletions src/Kdyby/Doctrine/Exception/DuplicateEntryException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Kdyby\Doctrine\Exception;

use Doctrine;
use Kdyby\Doctrine\Exception;

/**
* @author Filip Procházka <filip@prochazka.su>
* @deprecated
*/
class DuplicateEntryException extends DBALException
{

/**
* @var array
*/
public $columns;


/**
* @param \Exception|\Throwable $previous
* @param array $columns
* @param string $query
* @param array $params
* @param \Doctrine\DBAL\Connection $connection
*/
public function __construct($previous, $columns = [], $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL)
{
parent::__construct($previous, $query, $params, $connection);
$this->columns = $columns;
}


/**
* @return array
*/
public function __sleep()
{
return array_merge(parent::__sleep(), ['columns']);
}

}

class_alias(DuplicateEntryException::class, 'Kdyby\Doctrine\DuplicateEntryException');
44 changes: 44 additions & 0 deletions src/Kdyby/Doctrine/Exception/EmptyValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Kdyby\Doctrine\Exception;

use Doctrine;

/**
* @author Filip Procházka <filip@prochazka.su>
* @deprecated
*/
class EmptyValueException extends DBALException
{

/**
* @var string|NULL
*/
public $column;


/**
* @param \Exception|\Throwable $previous
* @param string|NULL $column
* @param string $query
* @param array $params
* @param \Doctrine\DBAL\Connection $connection
*/
public function __construct($previous, $column = NULL, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL)
{
parent::__construct($previous, $query, $params, $connection);
$this->column = $column;
}


/**
* @return array
*/
public function __sleep()
{
return array_merge(parent::__sleep(), ['column']);
}

}

class_alias(EmptyValueException::class, 'Kdyby\Doctrine\EmptyValueException');
Loading

0 comments on commit 98ade15

Please sign in to comment.