Skip to content

Commit

Permalink
return types
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Mar 23, 2017
1 parent 73acdf8 commit 7ff1577
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 67 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"prefer-stable": true,
"require": {
"php": "^7.0",
"doctrine/common": "^2.0",
"doctrine/inflector": "^1.0",
"zendframework/zend-paginator": "^2.6"
},
Expand All @@ -32,6 +33,7 @@
"humbug/humbug": "~1.0@dev",
"phpmetrics/phpmetrics": "^2.0",
"phpmd/phpmd": "^2.0",
"phpstan/phpstan": "~0.6",
"phpunit/phpunit": "^4.5|^5.0",
"phpunit/phpunit-mock-objects": "^3.2",
"sebastian/phpcpd": "^2.0",
Expand Down Expand Up @@ -62,6 +64,7 @@
"phpcs": "phpcs --standard=PSR2 src tests",
"phpcs-lint": "php-cs-fixer fix --dry-run --verbose",
"phpcpd": "phpcpd src",
"phpstan": "phpstan analyse --level 1 src tests",
"phpmd": "phpmd src text unusedcode,naming,design,controversial,codesize",
"phpmetrics": "phpmetrics --failure-condition='average.maintainabilityIndex < 50' src",
"phpmetrics-report": "phpmetrics --report-html=build/metrics/index.html --offline src",
Expand All @@ -75,6 +78,7 @@
"@phpcs-lint",
"@phpcpd",
"@phpmd",
"@phpstan",
"@phpmetrics"
],
"reports": [
Expand Down
25 changes: 14 additions & 11 deletions src/EventsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\EventManager;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\ObjectManager;

/**
* Events trait.
Expand Down Expand Up @@ -75,7 +76,7 @@ public function restoreEventSubscribers()
*
* @param string $event
*/
public function disableEventListeners($event)
public function disableEventListeners(string $event)
{
if (!array_key_exists($event, $this->disabledListeners)) {
$this->disabledListeners[$event] = [];
Expand All @@ -91,10 +92,12 @@ public function disableEventListeners($event)
/**
* Disable listener for an event.
*
* @param string $event
* @param \Doctrine\Common\EventSubscriber|string $subscriberClass
* @param string $event
* @param string|EventSubscriber $subscriberClass
*
* @throws \InvalidArgumentException
*/
public function disableEventListener($event, $subscriberClass)
public function disableEventListener(string $event, $subscriberClass)
{
$subscriberClass = $this->getSubscriberClassName($subscriberClass);

Expand Down Expand Up @@ -132,7 +135,7 @@ public function restoreAllEventListeners()
*
* @param string $event
*/
public function restoreEventListeners($event)
public function restoreEventListeners(string $event)
{
if (!array_key_exists($event, $this->disabledListeners) || empty($this->disabledListeners[$event])) {
return;
Expand All @@ -157,7 +160,7 @@ public function restoreEventListeners($event)
*
* @return string
*/
protected function getSubscriberClassName($subscriberClass)
protected function getSubscriberClassName($subscriberClass): string
{
if (is_object($subscriberClass) && in_array(EventSubscriber::class, class_implements($subscriberClass))) {
return get_class($subscriberClass);
Expand All @@ -178,7 +181,7 @@ protected function getSubscriberClassName($subscriberClass)
*
* @return array
*/
public function getRegisteredEvents()
public function getRegisteredEvents(): array
{
return array_keys($this->getEventManager()->getListeners());
}
Expand All @@ -190,7 +193,7 @@ public function getRegisteredEvents()
*
* @return EventSubscriber[]
*/
protected function getEventListeners($event = null)
protected function getEventListeners($event = null): array
{
$eventManager = $this->getEventManager();

Expand All @@ -202,15 +205,15 @@ protected function getEventListeners($event = null)
*
* @return EventManager
*/
protected function getEventManager()
protected function getEventManager(): EventManager
{
return $this->getManager()->getEventManager();
}

/**
* Get object manager.
*
* @return \Doctrine\ORM\EntityManager|\Doctrine\ODM\MongoDB\DocumentManager|\Doctrine\ODM\CouchDB\DocumentManager
* @return ObjectManager
*/
abstract protected function getManager();
abstract protected function getManager(): ObjectManager;
}
2 changes: 1 addition & 1 deletion src/PaginatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait PaginatorTrait
*
* @return Paginator
*/
protected function getPaginator(AdapterInterface $adapter, $itemsPerPage)
protected function getPaginator(AdapterInterface $adapter, int $itemsPerPage): Paginator
{
$paginator = new Paginator($adapter);
$paginator->setItemCountPerPage(max(-1, (int) $itemsPerPage));
Expand Down
44 changes: 26 additions & 18 deletions src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Jgut\Doctrine\Repository;

use Doctrine\Common\Persistence\ObjectRepository;
use Zend\Paginator\Paginator;

/**
* Repository interface.
Expand All @@ -25,14 +26,14 @@ interface Repository extends ObjectRepository
*
* @return bool
*/
public function isAutoFlush();
public function isAutoFlush(): bool;

/**
* Set automatic manager flushing.
*
* @param bool $autoFlush
*/
public function setAutoFlush($autoFlush = false);
public function setAutoFlush(bool $autoFlush = false);

/**
* Manager flush.
Expand Down Expand Up @@ -63,15 +64,15 @@ public function restoreEventSubscribers();
*
* @param string $event
*/
public function disableEventListeners($event);
public function disableEventListeners(string $event);

/**
* Disable listener for an event.
*
* @param string $event
* @param \Doctrine\Common\EventSubscriber|string $subscriberClass
* @param string|\Doctrine\Common\EventSubscriber $subscriberClass
*/
public function disableEventListener($event, $subscriberClass);
public function disableEventListener(string $event, $subscriberClass);

/**
* Restore all disabled listeners.
Expand All @@ -83,7 +84,14 @@ public function restoreAllEventListeners();
*
* @param string $event
*/
public function restoreEventListeners($event);
public function restoreEventListeners(string $event);

/**
* Get registered events.
*
* @return array
*/
public function getRegisteredEvents(): array;

/**
* Return paginated elements filtered by criteria.
Expand All @@ -92,18 +100,18 @@ public function restoreEventListeners($event);
* @param array $orderBy
* @param int $itemsPerPage
*
* @return \Zend\Paginator\Paginator
* @return Paginator
*/
public function findPaginatedBy($criteria, array $orderBy = [], $itemsPerPage = 10);
public function findPaginatedBy($criteria, array $orderBy = [], int $itemsPerPage = 10): Paginator;

/**
* Find one object by a set of criteria or create a new one.
*
* @param array|\Doctrine\ORM\QueryBuilder|\Doctrine\ODM\MongoDB\Query\Builder $criteria
* @param array $criteria
*
* @return \stdClass
*/
public function findOneByOrGetNew($criteria);
public function findOneByOrGetNew(array $criteria);

/**
* Get a new managed object instance.
Expand All @@ -118,52 +126,52 @@ public function getNew();
* @param \stdClass|\stdClass[] $objects
* @param bool $flush
*/
public function add($objects, $flush = false);
public function add($objects, bool $flush = false);

/**
* Remove all objects.
*
* @param bool $flush
*/
public function removeAll($flush = false);
public function removeAll(bool $flush = false);

/**
* Remove object filtered by a set of criteria.
*
* @param array $criteria
* @param bool $flush
*/
public function removeBy(array $criteria, $flush = false);
public function removeBy(array $criteria, bool $flush = false);

/**
* Remove first object filtered by a set of criteria.
*
* @param array $criteria
* @param bool $flush
*/
public function removeOneBy(array $criteria, $flush = false);
public function removeOneBy(array $criteria, bool $flush = false);

/**
* Remove objects.
*
* @param \stdClass|\stdClass[]|string|int $objects
* @param bool $flush
*/
public function remove($objects, $flush = false);
public function remove($objects, bool $flush = false);

/**
* Get all objects count.
*
* @return int
*/
public function countAll();
public function countAll(): int;

/**
* Get object count filtered by a set of criteria.
*
* @param array|\Doctrine\ORM\QueryBuilder $criteria
* @param mixed $criteria
*
* @return int
*/
public function countBy($criteria);
public function countBy($criteria): int;
}

0 comments on commit 7ff1577

Please sign in to comment.