Skip to content

Commit

Permalink
Merge pull request #3 from Bocmah/master
Browse files Browse the repository at this point in the history
Remove unused dependency on doctrine/common
  • Loading branch information
tanigami authored Jun 6, 2023
2 parents 42793ec + 9da6584 commit e629d17
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 75 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
}
],
"require": {
"php": ">=7.0",
"doctrine/common": "^2.8"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.4",
Expand Down
29 changes: 14 additions & 15 deletions src/AndSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

namespace Tanigami\Specification;

/**
* @template T
* @extends Specification<T>
*/
class AndSpecification extends Specification
{
/**
* @var Specification
* @var Specification<T>
*/
private $one;

/**
* @var Specification
* @var Specification<T>
*/
private $other;

/**
* @param Specification $one
* @param Specification $other
* @param Specification<T> $one
* @param Specification<T> $other
*/
public function __construct(Specification $one, Specification $other)
{
Expand All @@ -25,37 +29,32 @@ public function __construct(Specification $one, Specification $other)
}

/**
* {@inheritdoc}
* @param T $object
*/
public function isSatisfiedBy($object): bool
{
return $this->one->isSatisfiedBy($object) && $this->other->isSatisfiedBy($object);
}

/**
* {@inheritdoc}
*/
public function whereExpression(string $alias): string
{
return sprintf(
sprintf(
'(%s) AND (%s)',
$this->one()->whereExpression($alias),
$this->other()->whereExpression($alias)
)
'(%s) AND (%s)',
$this->one()->whereExpression($alias),
$this->other()->whereExpression($alias)
);
}

/**
* @return Specification
* @return Specification<T>
*/
public function one(): Specification
{
return $this->one;
}

/**
* @return Specification
* @return Specification<T>
*/
public function other(): Specification
{
Expand Down
17 changes: 9 additions & 8 deletions src/AnyOfSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

namespace Tanigami\Specification;

/**
* @template T
* @extends Specification<T>
*/
class AnyOfSpecification extends Specification
{
/**
* @var Specification[]
* @var Specification<T>[]
*/
private $specifications;

/**
* @param Specification[] ...$specifications
* @param Specification<T> ...$specifications
*/
public function __construct(Specification ...$specifications)
{
$this->specifications = $specifications;
}

/**
* {@inheritdoc}
* @param T $object
*/
public function isSatisfiedBy($object): bool
{
Expand All @@ -31,21 +35,18 @@ public function isSatisfiedBy($object): bool
return true;
}

/**
* {@inheritdoc}
*/
public function whereExpression(string $alias): string
{
return implode(' AND ', array_map(
function (Specification $specification) use ($alias) {
static function (Specification $specification) use ($alias) {
return '(' . $specification->whereExpression($alias) . ')';
},
$this->specifications
));
}

/**
* @return Specification[]
* @return Specification<T>[]
*/
public function specifications(): array
{
Expand Down
14 changes: 9 additions & 5 deletions src/NoneOfSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

namespace Tanigami\Specification;

/**
* @template T
* @extends Specification<T>
*/
class NoneOfSpecification extends Specification
{
/**
* @var Specification[]
* @var Specification<T>[]
*/
private $specifications;

/**
* @param Specification[] ...$specifications
* @param Specification<T> ...$specifications
*/
public function __construct(Specification ...$specifications)
{
$this->specifications = $specifications;
}

/**
* {@inheritdoc}
* @param T $object
*/
public function isSatisfiedBy($object): bool
{
Expand All @@ -32,10 +36,10 @@ public function isSatisfiedBy($object): bool
}

/**
* @return Specification[]
* @return Specification<T>[]
*/
public function specifications(): array
{
return $this->specifications();
return $this->specifications;
}
}
13 changes: 8 additions & 5 deletions src/NotSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@

namespace Tanigami\Specification;

/**
* @template T
* @extends Specification<T>
*/
class NotSpecification extends Specification
{
/**
* @var Specification
* @var Specification<T>
*/
private $specification;

/**
* @param Specification $specification
* @param Specification<T> $specification
*/
public function __construct(Specification $specification)
{
$this->specification = $specification;
}

/**
* @param mixed $object
* @return bool
* @param T $object
*/
public function isSatisfiedBy($object): bool
{
return !$this->specification->isSatisfiedBy($object);
}

/**
* @return Specification
* @return Specification<T>
*/
public function specification(): Specification
{
Expand Down
17 changes: 9 additions & 8 deletions src/OneOfSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

namespace Tanigami\Specification;

/**
* @template T
* @extends Specification<T>
*/
class OneOfSpecification extends Specification
{
/**
* @var Specification[]
* @var Specification<T>[]
*/
private $specifications;

/**
* @param Specification[] ...$specifications
* @param Specification<T> ...$specifications
*/
public function __construct(Specification ...$specifications)
{
$this->specifications = $specifications;
}

/**
* {@inheritdoc}
* @param T $object
*/
public function isSatisfiedBy($object): bool
{
Expand All @@ -31,21 +35,18 @@ public function isSatisfiedBy($object): bool
return false;
}

/**
* {@inheritdoc}
*/
public function whereExpression(string $alias): string
{
return implode(' OR ', array_map(
function (Specification $specification) use ($alias) {
static function (Specification $specification) use ($alias) {
return '(' . $specification->whereExpression($alias) . ')';
},
$this->specifications
));
}

/**
* @return Specification[]
* @return Specification<T>[]
*/
public function specifications(): array
{
Expand Down
29 changes: 14 additions & 15 deletions src/OrSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

namespace Tanigami\Specification;

/**
* @template T
* @extends Specification<T>
*/
class OrSpecification extends Specification
{
/**
* @var Specification
* @var Specification<T>
*/
private $one;

/**
* @var Specification
* @var Specification<T>
*/
private $other;

/**
* @param Specification $one
* @param Specification $other
* @param Specification<T> $one
* @param Specification<T> $other
*/
public function __construct(Specification $one, Specification $other)
{
Expand All @@ -25,37 +29,32 @@ public function __construct(Specification $one, Specification $other)
}

/**
* {@inheritdoc}
* @param T $object
*/
public function isSatisfiedBy($object): bool
{
return $this->one->isSatisfiedBy($object) || $this->other->isSatisfiedBy($object);
}

/**
* {@inheritdoc}
*/
public function whereExpression(string $alias): string
{
return sprintf(
sprintf(
'(%s) OR (%s)',
$this->one()->whereExpression($alias),
$this->other()->whereExpression($alias)
)
'(%s) OR (%s)',
$this->one()->whereExpression($alias),
$this->other()->whereExpression($alias)
);
}

/**
* @return Specification
* @return Specification<T>
*/
public function one(): Specification
{
return $this->one;
}

/**
* @return Specification
* @return Specification<T>
*/
public function other(): Specification
{
Expand Down
Loading

0 comments on commit e629d17

Please sign in to comment.