Skip to content

Commit

Permalink
Fix Scrutinizer-reported issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Miu committed Feb 26, 2020
1 parent 48bf7f9 commit 19da565
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/Behaviour/SoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Sirius\Orm\Behaviour;

use Sirius\Orm\Action\ActionInterface;
use Sirius\Orm\Action\BaseAction;
use Sirius\Orm\Action\Delete;
use Sirius\Orm\Mapper;
use Sirius\Orm\Query;

Expand All @@ -25,12 +27,12 @@ public function getName()
return 'soft_delete';
}

public function onDelete(Mapper $mapper, ActionInterface $delete)
public function onDelete(Mapper $mapper, Delete $delete)
{
return new \Sirius\Orm\Action\SoftDelete($mapper, $delete->getEntity(), ['deleted_at_column' => $this->column]);
}

public function onNewQuery(Mapper $mapper, Query $query)
public function onNewQuery(/** @scrutinizer ignore-unused */Mapper $mapper, Query $query)
{
$query->setGuards([
$this->column => null
Expand Down
2 changes: 1 addition & 1 deletion src/Behaviour/Timestamps.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getName()
return 'timestamps';
}

public function onSave(Mapper $mapper, ActionInterface $action)
public function onSave(/** @scrutinizer ignore-unused */Mapper $mapper, ActionInterface $action)
{
if ($action instanceof Insert) {
if ($this->createColumn) {
Expand Down
3 changes: 2 additions & 1 deletion src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(array $elements = [], callable $castingFunction = nu

protected function castElement($data)
{
return $this->castingFunction ? $this->castingFunction($data) : $data;
$castFunction = $this->castingFunction;
return $castFunction ? call_user_func($castFunction, $data) : $data;
}

public function add($element)
Expand Down
2 changes: 0 additions & 2 deletions src/ConnectionLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Sirius\Orm;

use Atlas\Pdo\Connection;

class ConnectionLocator extends \Atlas\Pdo\ConnectionLocator
{
public static function new(...$args)
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/GenericEntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class GenericEntityHydrator implements HydratorInterface
{
/**
* @var $castingManager
* @var CastingManager
*/
protected $castingManager;

Expand Down
7 changes: 5 additions & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ public function paginate($perPage, $page): PaginatedCollection
return $this->mapper->newPaginatedCollectionFromRows($this->fetchAll(), $total, $perPage, $page, $this->load);
}

public function chunk($count, $callback)
/**
* @todo implement this feature
*/
/*public function chunk($count, $callback)
{
}
}*/

public function count()
{
Expand Down
14 changes: 13 additions & 1 deletion src/Relation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

class Aggregate
{
/**
* @var string
*/
protected $name;
/**
* @var Relation
*/
protected $relation;
/**
* @var array
*/
protected $options;

public function __construct(string $name, Relation $relation, array $options)
{
$this->name = $name;
Expand Down Expand Up @@ -50,7 +63,6 @@ public function attachLazyAggregateToEntity(EntityInterface $entity, Tracker $tr

public function attachAggregateToEntity(EntityInterface $entity, array $results)
{
$keys = $this->relation->getKeyPairs();
$found = null;
foreach ($results as $row) {
if ($this->entityMatchesRow($entity, $row)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/HasAggregates.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public function getAggregates()

return $this->aggregates;
}

abstract public function getOption($name);
}
3 changes: 0 additions & 3 deletions src/Relation/ManyToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private function addPivotColumns($query)

public function joinSubselect(Query $query, string $reference)
{
$tableRef = $this->foreignMapper->getTableAlias(true);
$subselect = $query->subSelectForJoinWith()
->from($this->foreignMapper->getTable())
->columns($this->foreignMapper->getTable() . '.*')
Expand Down Expand Up @@ -194,7 +193,6 @@ public function detachEntities(EntityInterface $nativeEntity, EntityInterface $f
protected function addActionOnDelete(BaseAction $action)
{
$nativeEntity = $action->getEntity();
$nativeEntityKey = $nativeEntity->getPk();
$remainingRelations = $this->getRemainingRelations($action->getOption('relations'));

// no cascade delete? treat as save so we can process the changes
Expand All @@ -220,7 +218,6 @@ protected function addActionOnSave(BaseAction $action)
{
$remainingRelations = $this->getRemainingRelations($action->getOption('relations'));

/** @var Collection $foreignEntities */
$foreignEntities = $this->nativeMapper->getEntityAttribute($action->getEntity(), $this->name);
if (! $foreignEntities) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/Relation/OneToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function getQuery(Tracker $tracker)

public function joinSubselect(Query $query, string $reference)
{
$tableRef = $this->foreignMapper->getTableAlias(true);
$subselect = $query->subSelectForJoinWith()
->columns($this->foreignMapper->getTable() . '.*')
->from($this->foreignMapper->getTable())
Expand Down
2 changes: 1 addition & 1 deletion tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Sirius\Orm\Tests;

use Atlas\Pdo\Connection;
use Sirius\Orm\Connection;
use PHPUnit\Framework\TestCase;
use Sirius\Orm\ConnectionLocator;
use Sirius\Orm\Orm;
Expand Down

0 comments on commit 19da565

Please sign in to comment.