Skip to content

Commit 1bf74d7

Browse files
committed
moving from php-cs to laravel pint
1 parent a640cbb commit 1bf74d7

File tree

8 files changed

+40
-80
lines changed

8 files changed

+40
-80
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: vendor/bin/phpunit
4040

4141
- name: Run coding standard checks
42-
run: vendor/bin/php-cs-fixer fix
42+
run: vendor/bin/pint
4343

4444
- name: Auto-commit php-cs-fixer changes
4545
uses: stefanzweifel/git-auto-commit-action@v4

.php-cs-fixer.php

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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"illuminate/support": "^8.0|^9.0|^10|^11"
2222
},
2323
"require-dev": {
24-
"friendsofphp/php-cs-fixer": "^3.51",
24+
"laravel/pint": "^1.21",
2525
"nunomaduro/larastan": "^1.0",
2626
"orchestra/testbench": "^6.23.0|^7.0.0",
2727
"phpunit/phpunit": "^9.3.9"

ping.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "psr12"
3+
}

src/LaravelCaseServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function register()
2121
if ($caseBuilder instanceof Closure) {
2222
$callback = $caseBuilder;
2323

24-
$callback($caseBuilder = new CaseBuilder($this, new Grammar()));
24+
$callback($caseBuilder = new CaseBuilder($this, new Grammar));
2525
}
2626

2727
/** @var Builder $this */
@@ -35,7 +35,7 @@ public function register()
3535

3636
$this->app->bind(
3737
CaseBuilder::class,
38-
fn ($app) => new CaseBuilder($app->make(Builder::class), new Grammar())
38+
fn ($app) => new CaseBuilder($app->make(Builder::class), new Grammar)
3939
);
4040
}
4141
}

src/Query/CaseBuilder.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ class CaseBuilder
3131

3232
public QueryBuilder $queryBuilder;
3333

34-
/**
35-
* @param QueryBuilder $queryBuilder
36-
* @param Grammar $grammar
37-
*/
3834
public function __construct(
3935
QueryBuilder $queryBuilder,
40-
Grammar $grammar
36+
Grammar $grammar
4137
) {
4238
$this->queryBuilder = $queryBuilder;
4339
$this->grammar = $grammar;
@@ -58,10 +54,11 @@ public function caseRaw($subject): self
5854
}
5955

6056
/**
61-
* @param mixed $column
62-
* @param mixed $operator
63-
* @param mixed $value
57+
* @param mixed $column
58+
* @param mixed $operator
59+
* @param mixed $value
6460
* @return $this
61+
*
6562
* @throws Throwable
6663
*/
6764
public function when($column, $operator = null, $value = null): self
@@ -76,7 +73,7 @@ public function when($column, $operator = null, $value = null): self
7673
CaseBuilderException::wrongWhenPosition()
7774
);
7875

79-
[ $value, $operator ] = $this->queryBuilder->prepareValueAndOperator(
76+
[$value, $operator] = $this->queryBuilder->prepareValueAndOperator(
8077
$value,
8178
$operator,
8279
func_num_args() === 2
@@ -86,20 +83,20 @@ public function when($column, $operator = null, $value = null): self
8683
$this->addBinding($value, 'when');
8784

8885
$this->whens[] = [
89-
'query' => $this->grammar->wrapColumn($column) . ' ' . $operator . ' ?',
86+
'query' => $this->grammar->wrapColumn($column).' '.$operator.' ?',
9087
'binding' => count($this->bindings['when']) - 1,
9188
];
9289
} elseif (is_null($value)) {
9390
$operator = $operator === '=' ? 'IS' : 'IS NOT';
9491

9592
$this->whens[] = [
96-
'query' => $this->grammar->wrapColumn($column) . ' ' . $operator . ' NULL',
93+
'query' => $this->grammar->wrapColumn($column).' '.$operator.' NULL',
9794
];
9895
} elseif ($operator) {
9996
$this->addBinding($operator, 'when');
10097

10198
$this->whens[] = [
102-
'query' => $this->grammar->wrapColumn($column) . ' ?',
99+
'query' => $this->grammar->wrapColumn($column).' ?',
103100
'binding' => count($this->bindings['when']) - 1,
104101
];
105102
} else {
@@ -247,9 +244,9 @@ public function toRaw(): string
247244
}
248245

249246
/**
250-
* @param mixed $value
251-
* @param string $type
247+
* @param mixed $value
252248
* @return $this
249+
*
253250
* @throws \Throwable
254251
*/
255252
public function addBinding($value, string $type): CaseBuilder

tests/CaseBuilderTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class CaseBuilderTest extends TestCase
1212
{
13-
public function testCanGenerateSimpleQuery()
13+
public function test_can_generate_simple_query()
1414
{
1515
/**
1616
* @var QueryCaseBuilder $caseQuery
@@ -24,12 +24,12 @@ public function testCanGenerateSimpleQuery()
2424
$this->assertSameSize($caseQuery->whens, $caseQuery->thens);
2525

2626
$this->assertEquals('case when `payment_status` = ? then ? else ? end', $caseQuery->toSql());
27-
$this->assertEquals([ 1, "Paid", "Due", ], $caseQuery->getBindings());
27+
$this->assertEquals([1, 'Paid', 'Due'], $caseQuery->getBindings());
2828
$this->assertCount(3, $caseQuery->getBindings());
2929
$this->assertEquals('case when `payment_status` = 1 then "Paid" else "Due" end', $caseQuery->toRaw());
3030
}
3131

32-
public function testCanGenerateComplexQuery()
32+
public function test_can_generate_complex_query()
3333
{
3434
/**
3535
* @var QueryCaseBuilder $caseQuery
@@ -48,12 +48,12 @@ public function testCanGenerateComplexQuery()
4848
$this->assertNotEmpty($caseQuery->else);
4949

5050
$this->assertEquals('case when `payment_status` = ? then ? when `payment_status` = ? then ? when `payment_status` <= ? then ? else ? end', $caseQuery->toSql());
51-
$this->assertEquals([ 1, "Paid", 2, "Due", 5, "Canceled", "Unknown" ], $caseQuery->getBindings());
51+
$this->assertEquals([1, 'Paid', 2, 'Due', 5, 'Canceled', 'Unknown'], $caseQuery->getBindings());
5252
$this->assertCount(7, $caseQuery->getBindings());
5353
$this->assertEquals('case when `payment_status` = 1 then "Paid" when `payment_status` = 2 then "Due" when `payment_status` <= 5 then "Canceled" else "Unknown" end', $caseQuery->toRaw());
5454
}
5555

56-
public function testCanGenerateComplexQueryWithNullishTypes()
56+
public function test_can_generate_complex_query_with_nullish_types()
5757
{
5858
/**
5959
* @var QueryCaseBuilder $caseQuery
@@ -72,12 +72,12 @@ public function testCanGenerateComplexQueryWithNullishTypes()
7272
$this->assertNotEmpty($caseQuery->else);
7373

7474
$this->assertEquals('case when `payment_date` > ? then ? when `payment_date` = ? then ? when `payment_date` IS NULL then ? else ? end', $caseQuery->toSql());
75-
$this->assertEquals([ 0, "Paid", 0, "Due", "Canceled", "Unknown" ], $caseQuery->getBindings());
75+
$this->assertEquals([0, 'Paid', 0, 'Due', 'Canceled', 'Unknown'], $caseQuery->getBindings());
7676
$this->assertCount(6, $caseQuery->getBindings());
7777
$this->assertEquals('case when `payment_date` > 0 then "Paid" when `payment_date` = 0 then "Due" when `payment_date` IS NULL then "Canceled" else "Unknown" end', $caseQuery->toRaw());
7878
}
7979

80-
public function testCanGenerateComplexQueryWithDotSeparatedColumns()
80+
public function test_can_generate_complex_query_with_dot_separated_columns()
8181
{
8282
/**
8383
* @var QueryCaseBuilder $caseQuery
@@ -96,12 +96,12 @@ public function testCanGenerateComplexQueryWithDotSeparatedColumns()
9696
$this->assertNotEmpty($caseQuery->else);
9797

9898
$this->assertEquals('case when `Invoices`.`payment_status` = ? then ? when `Invoices`.`payment_status` = ? then ? when `Invoices`.`payment_status` <= ? then ? else ? end', $caseQuery->toSql());
99-
$this->assertEquals([ 1, "Paid", 2, "Due", 5, "Canceled", "Unknown" ], $caseQuery->getBindings());
99+
$this->assertEquals([1, 'Paid', 2, 'Due', 5, 'Canceled', 'Unknown'], $caseQuery->getBindings());
100100
$this->assertCount(7, $caseQuery->getBindings());
101101
$this->assertEquals('case when `Invoices`.`payment_status` = 1 then "Paid" when `Invoices`.`payment_status` = 2 then "Due" when `Invoices`.`payment_status` <= 5 then "Canceled" else "Unknown" end', $caseQuery->toRaw());
102102
}
103103

104-
public function testCanUseRawQueries()
104+
public function test_can_use_raw_queries()
105105
{
106106
/**
107107
* @var QueryCaseBuilder $caseQuery
@@ -118,12 +118,12 @@ public function testCanUseRawQueries()
118118
$this->assertNotEmpty($caseQuery->else);
119119

120120
$this->assertEquals('case when payment_status IN (1,2,3) then Paid when payment_status >= 4 then ? else ? end', $caseQuery->toSql());
121-
$this->assertEquals([ "Due", "Unknown" ], $caseQuery->getBindings());
121+
$this->assertEquals(['Due', 'Unknown'], $caseQuery->getBindings());
122122
$this->assertCount(2, $caseQuery->getBindings());
123123
$this->assertEquals('case when payment_status IN (1,2,3) then Paid when payment_status >= 4 then "Due" else "Unknown" end', $caseQuery->toRaw());
124124
}
125125

126-
public function testCanGenerateRawCases()
126+
public function test_can_generate_raw_cases()
127127
{
128128
/**
129129
* @var QueryCaseBuilder $caseQuery
@@ -140,7 +140,7 @@ public function testCanGenerateRawCases()
140140
$this->assertEquals('case count(id) when 1 then 0 else 100 end', $caseQuery->toRaw());
141141
}
142142

143-
public function testThrowsElseIsPresent()
143+
public function test_throws_else_is_present()
144144
{
145145
$this->expectException(CaseBuilderException::class);
146146
$this->expectExceptionMessage('ELSE statement is already present. The CASE statement can have only one ELSE.');
@@ -151,7 +151,7 @@ public function testThrowsElseIsPresent()
151151
->else('Unknown');
152152
}
153153

154-
public function testThrowsNoConditionsPresent()
154+
public function test_throws_no_conditions_present()
155155
{
156156
$this->expectException(CaseBuilderException::class);
157157
$this->expectExceptionMessage('The CASE statement must have at least one WHEN/THEN condition.');
@@ -163,7 +163,7 @@ public function testThrowsNoConditionsPresent()
163163
$caseQuery->toSql();
164164
}
165165

166-
public function testThrowsNumberOfConditionsNotMatching()
166+
public function test_throws_number_of_conditions_not_matching()
167167
{
168168
$this->expectException(CaseBuilderException::class);
169169
$this->expectExceptionMessage('The CASE statement must have a matching number of WHEN/THEN conditions.');
@@ -175,7 +175,7 @@ public function testThrowsNumberOfConditionsNotMatching()
175175
$caseQuery->toSql();
176176
}
177177

178-
public function testThrowsSubjectMustBePresentWhenCaseOperatorNotUsed()
178+
public function test_throws_subject_must_be_present_when_case_operator_not_used()
179179
{
180180
$this->expectException(CaseBuilderException::class);
181181
$this->expectExceptionMessage('The CASE statement subject must be present when operator and column are not present.');
@@ -184,7 +184,7 @@ public function testThrowsSubjectMustBePresentWhenCaseOperatorNotUsed()
184184
->then('Paid');
185185
}
186186

187-
public function testThrowsThenCannotBeBeforeWhen()
187+
public function test_throws_then_cannot_be_before_when()
188188
{
189189
$this->expectException(CaseBuilderException::class);
190190
$this->expectExceptionMessage('THEN cannot be before WHEN on a CASE statement.');
@@ -193,7 +193,7 @@ public function testThrowsThenCannotBeBeforeWhen()
193193
->when('payment_status', 1);
194194
}
195195

196-
public function testThrowsElseCanOnlyBeAfterAWhenThen()
196+
public function test_throws_else_can_only_be_after_a_when_then()
197197
{
198198
$this->expectException(CaseBuilderException::class);
199199
$this->expectExceptionMessage('ELSE can only be set after a WHEN/THEN in a CASE statement.');
@@ -203,7 +203,7 @@ public function testThrowsElseCanOnlyBeAfterAWhenThen()
203203
->then('Due');
204204
}
205205

206-
public function testThrowsElseCanOnlyBeAfterAWhenThenMiddle()
206+
public function test_throws_else_can_only_be_after_a_when_then_middle()
207207
{
208208
$this->expectException(CaseBuilderException::class);
209209
$this->expectExceptionMessage('ELSE can only be set after a WHEN/THEN in a CASE statement.');
@@ -213,7 +213,7 @@ public function testThrowsElseCanOnlyBeAfterAWhenThenMiddle()
213213
->then('Due');
214214
}
215215

216-
public function testThrowsWrongWhenPosition()
216+
public function test_throws_wrong_when_position()
217217
{
218218
$this->expectException(CaseBuilderException::class);
219219
$this->expectExceptionMessage('Wrong WHEN position.');
@@ -224,7 +224,7 @@ public function testThrowsWrongWhenPosition()
224224
->when('payment_status', 3);
225225
}
226226

227-
public function testToQueryReturnsQueryBuilder()
227+
public function test_to_query_returns_query_builder()
228228
{
229229
/**
230230
* @var QueryCaseBuilder $caseQuery
@@ -235,7 +235,7 @@ public function testToQueryReturnsQueryBuilder()
235235
$this->assertInstanceOf(Builder::class, $caseQuery->toQuery());
236236
}
237237

238-
public function testWithQueryBuilder()
238+
public function test_with_query_builder()
239239
{
240240
$query = DB::table('invoices')
241241
->where('active', true)

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ abstract class TestCase extends Orchestra
99
{
1010
protected function getPackageProviders($app)
1111
{
12-
return [ LaravelCaseServiceProvider::class, ];
12+
return [LaravelCaseServiceProvider::class];
1313
}
1414
}

0 commit comments

Comments
 (0)