Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 4da985e

Browse files
committed
✨ internal improvements and php 8.2 support
1 parent 3699ea0 commit 4da985e

File tree

9 files changed

+59
-132
lines changed

9 files changed

+59
-132
lines changed

.github/workflows/codecov.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,23 @@ name: codecov
22

33
on:
44
push:
5-
paths:
6-
- '**.php'
7-
- '.github/workflows/codecov.yml'
8-
- 'composer.lock'
9-
- 'composer.json'
105
pull_request:
11-
paths:
12-
- '**.php'
13-
- '.github/workflows/codecov.yml'
14-
- 'composer.lock'
15-
- 'composer.json'
166

177
jobs:
188
codecov:
199
runs-on: ubuntu-latest
2010

2111
steps:
22-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
2313

2414
- name: Setup PHP
2515
uses: shivammathur/setup-php@v2
2616
with:
2717
php-version: 8.1
18+
extensions: dom, libxml, mbstring
19+
ini-values: error_reporting=E_ALL
2820
coverage: xdebug
2921

30-
- name: Cache composer dependencies
31-
uses: actions/cache@v2
32-
with:
33-
path: vendor
34-
key: composer-${{ hashFiles('composer.lock') }}
35-
3622
- name: Install dependencies
3723
run: composer install --prefer-dist --no-interaction
3824

.github/workflows/php-cs-fixer.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,25 @@ name: php-cs-fixer
22

33
on:
44
push:
5-
paths:
6-
- '**.php'
7-
- '.github/workflows/php-cs-fixer.yml'
8-
- 'composer.lock'
95
pull_request:
10-
paths:
11-
- '**.php'
12-
- '.github/workflows/php-cs-fixer.yml'
13-
- 'composer.lock'
146

157
jobs:
168
php-cs-fixer:
179
runs-on: ubuntu-latest
1810

1911
steps:
20-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
2113

2214
- name: Setup php
2315
uses: shivammathur/setup-php@v2
2416
with:
2517
php-version: 8.0
18+
extensions: dom, libxml, mbstring
19+
ini-values: error_reporting=E_ALL
2620
coverage: none
2721

28-
- name: Cache composer dependencies
29-
uses: actions/cache@v2
30-
with:
31-
path: vendor
32-
key: composer-${{ hashFiles('composer.lock') }}
33-
3422
- name: Install dependencies
3523
run: composer install --prefer-dist --no-interaction
3624

3725
- name: Run php-cs-fixer
38-
run: vendor/bin/php-cs-fixer fix --dry-run
26+
run: composer php-cs-fixer

.github/workflows/phpstan.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,30 @@ name: phpstan
22

33
on:
44
push:
5-
paths:
6-
- '**.php'
7-
- '.github/workflows/phpstan.yml'
8-
- 'composer.lock'
95
pull_request:
10-
paths:
11-
- '**.php'
12-
- '.github/workflows/phpstan.yml'
13-
- 'composer.lock'
146

157
jobs:
168
phpstan:
179
runs-on: ubuntu-latest
1810
strategy:
1911
matrix:
20-
php: [ 8.0, 8.1 ]
12+
php: [ 8.0, 8.1, 8.2 ]
2113

2214
name: php@${{ matrix.php }}
2315

2416
steps:
25-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
2618

2719
- name: Setup PHP
2820
uses: shivammathur/setup-php@v2
2921
with:
3022
php-version: ${{ matrix.php }}
23+
extensions: dom, libxml, mbstring
24+
ini-values: error_reporting=E_ALL
3125
coverage: none
3226

33-
- name: Cache composer dependencies
34-
uses: actions/cache@v2
35-
with:
36-
path: vendor
37-
key: composer-${{ hashFiles('composer.lock') }}
38-
3927
- name: Install dependencies
4028
run: composer install --prefer-dist --no-interaction
4129

4230
- name: Run phpstan
43-
run: vendor/bin/phpstan --error-format=github
31+
run: composer phpstan:github

.github/workflows/tests.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
1-
name: tests
1+
name: Tests
22

33
on:
44
push:
5-
paths:
6-
- '**.php'
7-
- '.github/workflows/tests.yml'
8-
- 'composer.lock'
95
pull_request:
10-
paths:
11-
- '**.php'
12-
- '.github/workflows/tests.yml'
13-
- 'composer.lock'
146

157
jobs:
168
phpunit:
179
runs-on: ubuntu-latest
1810
strategy:
11+
fail-fast: true
1912
matrix:
20-
php: [ 8.0, 8.1 ]
13+
php: [ 8.0, 8.1, 8.2 ]
2114

2215
name: php@${{ matrix.php }}
2316

2417
steps:
25-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
2619

2720
- name: Setup php
2821
uses: shivammathur/setup-php@v2
2922
with:
3023
php-version: ${{ matrix.php }}
3124
extensions: dom, libxml, mbstring
25+
ini-values: error_reporting=E_ALL
3226
coverage: none
3327

34-
- name: Cache composer dependencies
35-
uses: actions/cache@v2
36-
with:
37-
path: vendor
38-
key: composer-${{ hashFiles('composer.lock') }}
39-
4028
- name: Install dependencies
4129
run: composer install --prefer-dist --no-interaction
4230

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@
4545
"autoload-dev": {
4646
"psr-4": {
4747
"JqlBuilder\\Tests\\": "tests"
48-
},
49-
"files": [
50-
"src/helpers.php"
51-
]
48+
}
5249
},
5350
"extra": {
5451
"laravel": {
@@ -67,6 +64,7 @@
6764
"php-cs-fixer": "php-cs-fixer fix --dry-run",
6865
"php-cs-fixer:fix": "php-cs-fixer fix",
6966
"phpstan": "phpstan analyse",
67+
"phpstan:github": "phpstan analyse --error-format=github",
7068
"test": "phpunit"
7169
}
7270
}

phpstan.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
parameters:
2-
level: 8
2+
level: max
33

44
paths:
55
- src
66

77
ignoreErrors:
8+
- '#Parameter \#2 \$operator of method JqlBuilder\\Jql::invalidBooleanOrOperator\(\) expects string, mixed given.#'
9+
- '#Parameter \#1 \$operator of method JqlBuilder\\Jql::quote\(\) expects string, mixed given.#'
10+
- '#Part \$operator \(mixed\) of encapsed string cannot be cast to string.#'
11+
- '#Parameter \#3 \$subject of function str_replace expects array\|string, mixed given.#'
12+
- '#Parameter \#2 ...\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given.#'

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
9+
convertDeprecationsToExceptions="true"
910
processIsolation="false"
1011
stopOnFailure="false"
1112
verbose="true"

src/Jql.php

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ public function where(
2222
string $boolean = Keyword::AND
2323
): self {
2424
if ($column instanceof Closure) {
25-
return tap($this, function () use ($boolean, $column) {
26-
if (empty($this->query)) {
27-
$queryTemplate = "(%s)";
28-
} else {
29-
$queryTemplate = "$this->query $boolean (%s)";
30-
$this->query = '';
31-
}
25+
if (empty($this->query)) {
26+
$queryTemplate = "(%s)";
27+
} else {
28+
$queryTemplate = "$this->query $boolean (%s)";
29+
$this->query = '';
30+
}
31+
32+
$column($this);
3233

33-
$column($this);
34+
$this->query = sprintf($queryTemplate, $this->query);
3435

35-
$this->query = sprintf($queryTemplate, $this->query);
36-
});
36+
return $this;
3737
}
3838

3939
if (count(func_get_args()) === 2) {
@@ -42,7 +42,9 @@ public function where(
4242

4343
$this->invalidBooleanOrOperator($boolean, $operator, $value);
4444

45-
return tap($this, fn () => $this->appendQuery("$column $operator {$this->quote($operator, $value)}", $boolean));
45+
$this->appendQuery("$column $operator {$this->quote($operator, $value)}", $boolean);
46+
47+
return $this;
4648
}
4749

4850
public function orWhere(string|Closure $column, mixed $operator = Operator::EQUALS, mixed $value = null): self
@@ -51,12 +53,14 @@ public function orWhere(string|Closure $column, mixed $operator = Operator::EQUA
5153
[$column, $operator, $value] = [$column, is_array($operator) ? Operator::IN : Operator::EQUALS, $operator];
5254
}
5355

54-
return tap($this, fn () => $this->where($column, $operator, $value, Keyword::OR));
56+
$this->where($column, $operator, $value, Keyword::OR);
57+
58+
return $this;
5559
}
5660

5761
public function when(mixed $value, callable $callback): self
5862
{
59-
$value = value($value, $this);
63+
$value = $value instanceof Closure ? $value($this) : $value;
6064

6165
if ($value) {
6266
return $callback($this, $value) ?: $this;
@@ -67,7 +71,7 @@ public function when(mixed $value, callable $callback): self
6771

6872
public function whenNot(mixed $value, callable $callback): self
6973
{
70-
$value = value($value, $this);
74+
$value = $value instanceof Closure ? $value($this) : $value;
7175

7276
if (! $value) {
7377
return $callback($this, $value) ?: $this;
@@ -78,12 +82,16 @@ public function whenNot(mixed $value, callable $callback): self
7882

7983
public function orderBy(string $column, string $direction): self
8084
{
81-
return tap($this, fn () => $this->appendQuery(Keyword::ORDER_BY." $column $direction"));
85+
$this->appendQuery(Keyword::ORDER_BY." $column $direction");
86+
87+
return $this;
8288
}
8389

8490
public function rawQuery(string $query): self
8591
{
86-
return tap($this, fn () => $this->appendQuery($query));
92+
$this->appendQuery($query);
93+
94+
return $this;
8795
}
8896

8997
public function getQuery(): string
@@ -99,13 +107,16 @@ public function __toString(): string
99107
private function quote(string $operator, mixed $value): string
100108
{
101109
if (in_array($operator, [Operator::IN, Operator::NOT_IN, Operator::WAS_IN, Operator::WAS_NOT_IN])) {
102-
$values = array_reduce(array_wrap($value), function ($prev, $current) {
103-
if ($prev === null) {
104-
return '"'.str_replace('"', '\\"', $current).'"';
110+
$values = array_reduce(
111+
is_array($value) ? $value : [$value],
112+
function ($prev, $current) {
113+
if ($prev === null) {
114+
return '"'.str_replace('"', '\\"', $current).'"';
115+
}
116+
117+
return $prev.', "'.str_replace('"', '\\"', $current).'"';
105118
}
106-
107-
return $prev.', "'.str_replace('"', '\\"', $current).'"';
108-
});
119+
);
109120

110121
return "($values)";
111122
}

src/helpers.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)