Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade 8.3 #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

9 changes: 5 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/spec export-ignore
.coveralls.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
.php_cs export-ignore
phpspec.yml.dist export-ignore
.php-cs-fixer.php export-ignore
phpspec.yml export-ignore
rector.php export-ignore
phpstan.neon export-ignore
phpstan-baseline.neon export-ignore
43 changes: 43 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PHP Composer

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: docker compose run composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }}-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-php-${{ hashFiles('**/composer.json') }}
${{ runner.os }}-php-

- name: Install packages
run: docker compose run composer install

- name: Run test suite
run: docker compose run phpspec

- name: Run static analyzer
run: docker compose run phpstan

- name: Run code style checker
run: docker compose run php-cs-fixer --dry-run
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build/
coverage/
vendor/
.php_cs.cache
.php-cs-fixer.cache
composer.lock
17 changes: 17 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude(['vendor', 'build'])
->in(__DIR__);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'strict_comparison' => true,
'strict_param' => true,
])
->setFinder($finder);
26 changes: 0 additions & 26 deletions .php_cs

This file was deleted.

28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM php:8.3-cli-alpine
RUN apk add --no-cache --update --virtual .build-deps $PHPIZE_DEPS linux-headers \
&& pecl install xdebug-3.3.2 \
&& docker-php-ext-enable xdebug \
&& apk del -f .build-deps \
&& echo "xdebug.mode=coverage" >> $PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015 Rik Bruil
Copyright (c) 2024 Nicholas Ruunu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# Doctrine Specification
[![Build Status](https://travis-ci.org/rikbruil/Doctrine-Specification.svg)](https://travis-ci.org/rikbruil/Doctrine-Specification)
[![Coverage Status](https://coveralls.io/repos/rikbruil/Doctrine-Specification/badge.svg?branch=master)](https://coveralls.io/r/rikbruil/Doctrine-Specification?branch=master)
[![Latest Stable Version](https://poser.pugx.org/rikbruil/doctrine-specification/v/stable.svg)](https://packagist.org/packages/rikbruil/doctrine-specification)
[![License](https://poser.pugx.org/rikbruil/doctrine-specification/license.svg)](https://packagist.org/packages/rikbruil/doctrine-specification)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rikbruil/Doctrine-Specification/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/rikbruil/Doctrine-Specification/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/bb221821-1ba6-4613-b39f-f43718aaa92d/mini.png)](https://insight.sensiolabs.com/projects/bb221821-1ba6-4613-b39f-f43718aaa92d)
# Doctrine Specification

Doctrine [Specification pattern][specification_pattern] for building queries dynamically and with re-usable classes for composition.
Doctrine [Specification pattern][specification_pattern] for building queries dynamically and with re-usable classes for
composition.

This library started out as an adaptation of Benjamin Eberlei's [blog post][blog_post]. I was also inspired by the [Happyr Doctrine-Specification][happyr_spec] code, however this library has some small differences.
The main one is that SpecificationRepository->match() does not return the results directly, but returns the query object.
This library started out as an adaptation of Benjamin Eberlei's [blog post][blog_post]. I was also inspired by
the [Happyr Doctrine-Specification][happyr_spec] code, however this library has some small differences.
The main one is that SpecificationRepository->match() does not return the results directly, but returns the query
object.

Since I like Doctrine's Paginator object, I wanted to be able to use that in combination with the Specification pattern.

__Note:__ In versions prior to 1.2 it was required to extend the SpecificationRepository class. This is no longer needed since we provide a SpecificationRepositoryTrait that you can use instead.
The class is still provided for backwards compatibility reasons. There is also the SpecificationAwareInterface that you can use if you need it.
__Note:__ In versions prior to 1.2 it was required to extend the SpecificationRepository class. This is no longer needed
since we provide a SpecificationRepositoryTrait that you can use instead.
The class is still provided for backwards compatibility reasons. There is also the SpecificationAwareInterface that you
can use if you need it.

## Usage

Install the latest version with `composer require rikbruil/doctrine-specification`
Install the latest version with `composer require purist/doctrine-specification`

```php
// Not using the lib
Expand All @@ -43,12 +42,12 @@ return $qb->where('r.ended = 0')
```

```php
use Rb\Specification\Doctrine\Condition\Equals;
use Rb\Specification\Doctrine\Condition\IsNull;
use Rb\Specification\Doctrine\Condition\LessThan;
use Rb\Specification\Doctrine\Logic\AndX;
use Rb\Specification\Doctrine\Logic\OrX;
use Rb\Specification\Doctrine\Specification;
use Purist\Specification\Doctrine\Condition\Equals;
use Purist\Specification\Doctrine\Condition\IsNull;
use Purist\Specification\Doctrine\Condition\LessThan;
use Purist\Specification\Doctrine\Logic\AndX;
use Purist\Specification\Doctrine\Logic\OrX;
use Purist\Specification\Doctrine\Specification;

// Using the lib
$spec = new Specification([
Expand All @@ -67,6 +66,7 @@ return $this->em->getRepository('Advertisement')->match($spec)->execute();
```

## Composition

A bonus of this pattern is composition, which makes specifications very reusable:

```php
Expand All @@ -89,7 +89,7 @@ class ExpiredAds extends Specification
];
parent::__construct($specs);
}

public function isSatisfiedBy($value)
{
return $value === Advertisement::class;
Expand All @@ -107,7 +107,7 @@ class AdsByUser extends Specification
new Join('user', 'u'),
new Equals('id', $user->getId(), 'u'),
];

parent::__construct($specs);
}

Expand All @@ -131,7 +131,7 @@ class SomeService

return $this->em->getRepository('Advertisement')->match($spec)->execute();
}

/**
* Fetch adverts paginated by Doctrine Paginator with joins intact.
* A paginator can be iterated over like a normal array or Doctrine Collection
Expand All @@ -142,7 +142,7 @@ class SomeService
new ExpiredAds(),
new AdsByUser($user),
]);

$query = $this->em->getRepository('Advertisement')->match($spec);
$query->setFirstResult(($page - 1) * $size))
->setMaxResults($size);
Expand All @@ -155,7 +155,7 @@ class SomeService

Doctrine-Specification requires:

- PHP 5.5+
- PHP 8.3+
- Doctrine 2.2

## License
Expand Down
34 changes: 20 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
{
"name": "rikbruil/doctrine-specification",
"name": "purist/doctrine-specification",
"description": "Doctrine Specification pattern for building queries dynamically and with re-usable classes for composition.",
"type": "library",
"keywords": ["doctrine", "repository", "specification"],
"license": "MIT",
"authors": [
{
"name": "Rik Bruil",
"email": "rik.bruil@gmail.com"
"name": "Nicholas Ruunu",
"email": "nicholas@ruu.nu"
}
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {"Rb\\Specification\\Doctrine\\": "src/"}
"psr-4": {"Purist\\Specification\\Doctrine\\": "src/"}
},
"autoload-dev": {
"psr-4": {"spec\\Rb\\Specification\\Doctrine\\": "spec/"}
"psr-4": {"spec\\Purist\\Specification\\Doctrine\\": "spec/"}
},
"require": {
"php": ">=5.5",
"doctrine/orm": "^2.2",
"doctrine/collections": "^1.2",
"rikbruil/specification": "0.9.*"
"php": "^8.3",
"doctrine/orm": "^2.2|^3.0",
"doctrine/collections": "^2.0",
"purist/specification": "dev-master"
},
"require-dev": {
"phpspec/phpspec": "^2.0",
"henrikbjorn/phpspec-code-coverage": "^2.0",
"friendsofphp/php-cs-fixer": "^2.0",
"satooshi/php-coveralls": "^1.0"
"phpspec/phpspec": "^7.5",
"rector/rector": "^1.1",
"friendsofphp/php-cs-fixer": "^3.59",
"phpstan/phpstan": "^1.11",
"friends-of-phpspec/phpspec-code-coverage": "^6.3"
},
"extra": {
"branch-alias": {
Expand All @@ -36,6 +37,11 @@
},
"scripts": {
"test": "vendor/bin/phpspec run",
"static-analyzer": "vendor/bin/phpstan",
"check-style": "vendor/bin/php-cs-fixer fix --dry-run",
"fix-style": "vendor/bin/php-cs-fixer fix"
}
},
"repositories": [
{ "type": "git", "url": "https://github.com/PuristPHP/specification.git" }
]
}
25 changes: 25 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
php: &php
build: .
volumes:
- .:/app
working_dir: /app

phpspec:
<<: *php
entrypoint: vendor/bin/phpspec
command: run

phpstan:
<<: *php
entrypoint: vendor/bin/phpstan

php-cs-fixer:
<<: *php
entrypoint: vendor/bin/php-cs-fixer fix

composer:
image: composer:latest
volumes:
- .:/app
working_dir: /app
13 changes: 13 additions & 0 deletions phpspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
suites:
main:
namespace: Purist\Specification\Doctrine
psr4_prefix: Purist\Specification\Doctrine
extensions:
FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension:
format:
- text
- clover
- html
output:
html: coverage/html
clover: coverage/clover.xml
15 changes: 0 additions & 15 deletions phpspec.yml.dist

This file was deleted.

11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/Result/ModifierCollection.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/Specification.php
Loading
Loading