Skip to content

Commit

Permalink
Merge pull request #30 from ray-di/provider
Browse files Browse the repository at this point in the history
Bind SQL invokable object to the provider
  • Loading branch information
koriym authored Jun 10, 2024
2 parents 560f8b1 + 8911b1a commit 103efbc
Show file tree
Hide file tree
Showing 40 changed files with 916 additions and 781 deletions.
37 changes: 4 additions & 33 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,7 @@ on:
workflow_dispatch:

jobs:
coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Validate composer.json
run: composer validate --strict

- name: Run PHP_CodeSniffer
run: ./vendor/bin/phpcs -q --no-colors --report=checkstyle src tests | cs2pr
cs:
uses: ray-di/.github/.github/workflows/coding-standards.yml@v1
with:
php_version: 8.3
63 changes: 6 additions & 57 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,11 @@ on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '42 15 * * *'

jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
operating-system:
- ubuntu-latest
php-version:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
dependencies:
- lowest
- highest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
ini-values: zend.assertions=1

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install lowest dependencies
if: ${{ matrix.dependencies == 'lowest' }}
run: composer update --prefer-lowest --no-interaction --no-progress --no-suggest

- name: Install highest dependencies
if: ${{ matrix.dependencies == 'highest' }}
run: composer update --no-interaction --no-progress --no-suggest

- name: Run test suite
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage report
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml

- name: Run Demo
run: php demo/run.php
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@v1
with:
old_stable: '["7.3", "7.4", "8.0", "8.1", "8.2"]'
current_stable: 8.3
script: demo/run.php
135 changes: 4 additions & 131 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,134 +6,7 @@ on:
workflow_dispatch:

jobs:
static-analysis-phpstan:
name: Static Analysis with PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction --error-format=checkstyle | cs2pr

static-analysis-psalm:
name: Static Analysis with Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run Psalm
run: ./vendor/bin/psalm --show-info=false --output-format=checkstyle --shepherd | cs2pr

static-analysis-phpmd:
name: Static Analysis with PHPMD
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHP Mess Detector
run: ./vendor/bin/phpmd src text --exclude src/Annotation ./phpmd.xml

static-analysis-php-metrics:
name: Static Analysis with PhpMetrics
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PhpMetrics
run: ./vendor/bin/phpmetrics --exclude=Exception src

static-analysis-composer-require-checker:
name: Static Analysis with ComposerRequireChecker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: |
composer install --no-interaction --no-progress --prefer-dist
composer require --dev maglnet/composer-require-checker ^3.0
- name: Run composer-require-checker
run: ./vendor/bin/composer-require-checker
sa:
uses: ray-di/.github/.github/workflows/static-analysis.yml@v1
with:
php_version: 8.3
28 changes: 11 additions & 17 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
build:
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
environment:
php:
version: 8.2

filter:
paths: ["src/*"]
tools:
external_code_coverage: true
php_code_coverage: true
php_sim: true
php_mess_detector: true
php_pdepend: true
php_analyzer: true
php_cpd: true
php_mess_detector:
enabled: true
config:
ruleset: ./phpmd.xml
php_code_sniffer:
enabled: true
config:
ruleset: ./phpcs.xml
paths: ["src/*"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) <2018-2022> <Akihito Koriyama>
Copyright (c) <2018-2024> <Akihito Koriyama>

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 Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"bear/resource": "^1.15",
"doctrine/annotations": "^1.12",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"koriym/param-reader": "^1.0",
"koriym/query-locator": "^1.4",
"nikic/php-parser": "^v4.13",
"ray/aop": "^2.10.3",
"ray/aura-sql-module": "^1.10.0",
"ray/di": "^2.11",
"nikic/php-parser": "^v4.13"
"ray/di": "^2.11"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.6.19",
"bamarni/composer-bin-plugin": "^1.4"
},
"autoload": {
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ parameters:
paths:
- src
- tests
checkMissingIterableValueType: false
excludes_analyse:
- %currentWorkingDirectory%/tests/tmp/*
- %currentWorkingDirectory%/tests/Fake/*
5 changes: 3 additions & 2 deletions src-deprecated/SqlAliasInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Ray\Query;

use BEAR\Resource\ResourceObject;
use InvalidArgumentException;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use Ray\Aop\ReflectionMethod;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function invoke(MethodInvocation $invocation)
/** @var AliasQuery $aliasQuery */
$aliasQuery = $method->getAnnotation(AliasQuery::class);
$namedArguments = (array) $invocation->getNamedArguments();
list($queryId, $params) = $aliasQuery->templated ? $this->templated($aliasQuery, $namedArguments) : [$aliasQuery->id, $namedArguments];
[$queryId, $params] = $aliasQuery->templated ? $this->templated($aliasQuery, $namedArguments) : [$aliasQuery->id, $namedArguments];
$interface = $aliasQuery->type === 'row' ? RowInterface::class : RowListInterface::class;
$query = $this->injector->getInstance($interface, $queryId);
if ($query instanceof QueryInterface) {
Expand Down Expand Up @@ -76,7 +77,7 @@ private function templated(AliasQuery $aliasQuery, array $namedArguments) : arra
{
$url = parse_url(uri_template($aliasQuery->id, $namedArguments));
if (! $url) {
throw new \InvalidArgumentException($aliasQuery->id);
throw new InvalidArgumentException($aliasQuery->id);
}
$queryId = $url['path'];
isset($url['query']) ? parse_str($url['query'], $params) : $params = $namedArguments;
Expand Down
1 change: 1 addition & 0 deletions src/Annotation/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class Query
*/
public $type = 'row_list';

/** @SuppressWarnings(PHPMD.BooleanArgumentFlag) */
public function __construct(string $id, string $type = 'row_list', bool $templated = false)
{
$this->id = $id;
Expand Down
25 changes: 25 additions & 0 deletions src/Annotation/Sql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Ray\Query\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;

/**
* @Annotation
* @Target("PROPERTY")
* @NamedArgumentConstructor()
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
final class Sql
{
/** @var string */
public $sql;

public function __construct(string $sql)
{
$this->sql = $sql;
}
}
11 changes: 11 additions & 0 deletions src/Exception/SqlFileNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Ray\Query\Exception;

use LogicException;

class SqlFileNotFoundException extends LogicException
{
}
11 changes: 11 additions & 0 deletions src/Exception/SqlNotAnnotatedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Ray\Query\Exception;

use LogicException;

class SqlNotAnnotatedException extends LogicException
{
}
Loading

0 comments on commit 103efbc

Please sign in to comment.