Skip to content

Commit 4b2ba1b

Browse files
Merge pull request #14 from php-strictus/code-style-improvements
Code style improvements
2 parents 92d190c + 496fe76 commit 4b2ba1b

File tree

17 files changed

+81
-136
lines changed

17 files changed

+81
-136
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml,json}]
15+
indent_size = 2

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1818

1919
- name: Setup PHP
2020
uses: shivammathur/setup-php@v2

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
<div align="center">
2-
<p>
3-
<img src="https://github.com/php-strictus/strictus/raw/main/art/logo.png" alt="Strictus" width="400"/>
4-
<h1>Strictus</h1>
5-
Strict Typing on inline variables for PHP
6-
</p>
7-
8-
<p align="center">
9-
<a href="https://packagist.org/packages/strictus/strictus"><img src="https://img.shields.io/packagist/v/strictus/strictus.svg?style=flat-square" alt="Packagist"></a>
10-
<a href="https://packagist.org/packages/strictus/strictus"><img src="https://img.shields.io/packagist/php-v/strictus/strictus.svg?style=flat-square" alt="PHP from Packagist"></a>
11-
<a href="https://github.com/php-strictus/strictus/actions"><img alt="GitHub Workflow Status (main)" src="https://img.shields.io/github/actions/workflow/status/php-strictus/strictus/tests.yml?branch=main&label=Tests"> </a>
12-
</p>
13-
14-
<p align="center">
2+
<img src="https://github.com/php-strictus/strictus/raw/main/art/logo.png" alt="Strictus" width="400"/>
3+
<h1>Strictus</h1>
4+
<h4>Strict Typing on inline variables for PHP</h4>
5+
</div>
6+
7+
<div align="center">
8+
<a href="https://packagist.org/packages/strictus/strictus"><img src="https://img.shields.io/packagist/v/strictus/strictus.svg?style=flat-square" alt="Packagist"></a>
9+
<a href="https://packagist.org/packages/strictus/strictus"><img src="https://img.shields.io/packagist/php-v/strictus/strictus.svg?style=flat-square" alt="PHP from Packagist"></a>
10+
<a href="https://github.com/php-strictus/strictus/actions"><img alt="GitHub Workflow Status (main)" src="https://img.shields.io/github/actions/workflow/status/php-strictus/strictus/tests.yml?branch=main&label=Tests"> </a>
11+
</div>
12+
13+
<div align="center">
1514
<a href="#introduction">Introduction</a> |
1615
<a href="#installation">Installation</a> |
1716
<a href="#usage">Usage</a> |
1817
<a href="#credits">Credits</a> |
1918
<a href="#contributing">Contributing</a>
20-
</p>
2119
</div>
2220

2321
## Introduction
@@ -249,4 +247,4 @@ for PHP we quickly decided a package was the right approach whilst we could get
249247

250248
We welcome contributions!
251249

252-
Please visit the **[Contributing Guide](CONTRIBUTING.md)** to learn more about contributing to Strictus.
250+
Please visit the **[Contributing Guide](CONTRIBUTING.md)** to learn more about contributing to Strictus.

composer.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@
3030
"php": "^8.1"
3131
},
3232
"scripts": {
33-
"lint": "pint",
34-
"test:lint": "pint --test",
35-
"test:unit": "./vendor/bin/pest --order-by random",
36-
"test": ["@test:lint", "@test:unit"]
33+
"lint": ["pint"],
34+
"test:lint": ["pint --test"],
35+
"test:unit": ["pest --order-by random"],
36+
"test": [
37+
"@test:lint",
38+
"@test:unit"
39+
]
3740
},
3841
"require-dev": {
39-
"laravel/pint": "^1.4.1",
40-
"pestphp/pest": "^1.22.4"
42+
"laravel/pint": "^1.10.1",
43+
"pestphp/pest": "^1.23.0"
4144
},
4245
"config": {
4346
"sort-packages": true,

pint.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
{
22
"preset": "laravel",
33
"rules": {
4+
"array_push": true,
5+
"assign_null_coalescing_to_coalesce_equal": true,
6+
"combine_consecutive_issets": true,
7+
"combine_consecutive_unsets": true,
8+
"concat_space": {
9+
"spacing": "one"
10+
},
11+
"declare_strict_types": true,
12+
"explicit_indirect_variable": true,
13+
"explicit_string_variable": true,
14+
"global_namespace_import": true,
15+
"method_argument_space": {
16+
"on_multiline": "ensure_fully_multiline"
17+
},
18+
"modernize_strpos": true,
19+
"modernize_types_casting": true,
20+
"new_with_braces": true,
21+
"no_superfluous_elseif": true,
22+
"no_useless_else": true,
23+
"nullable_type_declaration_for_default_null_value": true,
424
"ordered_imports": {
525
"sort_algorithm": "alpha"
626
},
@@ -28,6 +48,9 @@
2848
"method_private"
2949
],
3050
"sort_algorithm": "none"
31-
}
51+
},
52+
"strict_comparison": true,
53+
"ternary_to_null_coalescing": true,
54+
"use_arrow_functions": true
3255
}
33-
}
56+
}

src/Interfaces/StrictusTypeInterface.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,9 @@
1111
*/
1212
interface StrictusTypeInterface
1313
{
14-
/**
15-
* @param string $value
16-
* @return mixed
17-
*/
1814
public function __get(string $value): mixed;
1915

20-
/**
21-
* @param string $name
22-
* @param mixed $value
23-
* @return void
24-
*/
2516
public function __set(string $name, mixed $value): void;
2617

27-
/**
28-
* @param mixed $value
29-
* @return mixed
30-
*/
3118
public function __invoke(mixed $value = new StrictusUndefined()): mixed;
3219
}

src/Strictus.php

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,136 +14,71 @@
1414

1515
final class Strictus
1616
{
17-
/**
18-
* @param mixed $string
19-
* @param bool $nullable
20-
* @return StrictusString
21-
*/
2217
public static function string(mixed $string, bool $nullable = false): StrictusString
2318
{
2419
return new StrictusString($string, $nullable);
2520
}
2621

27-
/**
28-
* @param mixed $string
29-
* @return StrictusString
30-
*/
3122
public static function nullableString(mixed $string): StrictusString
3223
{
3324
return new StrictusString($string, true);
3425
}
3526

36-
/**
37-
* @param mixed $integer
38-
* @param bool $nullable
39-
* @return StrictusInteger
40-
*/
4127
public static function int(mixed $integer, bool $nullable = false): StrictusInteger
4228
{
4329
return new StrictusInteger($integer, $nullable);
4430
}
4531

46-
/**
47-
* @param mixed $integer
48-
* @return StrictusInteger
49-
*/
5032
public static function nullableInt(mixed $integer): StrictusInteger
5133
{
5234
return new StrictusInteger($integer, true);
5335
}
5436

55-
/**
56-
* @param mixed $float
57-
* @param bool $nullable
58-
* @return StrictusFloat
59-
*/
6037
public static function float(mixed $float, bool $nullable = false): StrictusFloat
6138
{
6239
return new StrictusFloat($float, $nullable);
6340
}
6441

65-
/**
66-
* @param mixed $float
67-
* @return StrictusFloat
68-
*/
6942
public static function nullableFloat(mixed $float): StrictusFloat
7043
{
7144
return new StrictusFloat($float, true);
7245
}
7346

74-
/**
75-
* @param mixed $boolean
76-
* @param bool $nullable
77-
* @return StrictusBoolean
78-
*/
7947
public static function bool(mixed $boolean, bool $nullable = false): StrictusBoolean
8048
{
8149
return new StrictusBoolean($boolean, $nullable);
8250
}
8351

84-
/**
85-
* @param mixed $boolean
86-
* @return StrictusBoolean
87-
*/
8852
public static function nullableBool(mixed $boolean): StrictusBoolean
8953
{
9054
return new StrictusBoolean($boolean, true);
9155
}
9256

93-
/**
94-
* @param mixed $array
95-
* @param bool $nullable
96-
* @return StrictusArray
97-
*/
9857
public static function array(mixed $array, bool $nullable = false): StrictusArray
9958
{
10059
return new StrictusArray($array, $nullable);
10160
}
10261

103-
/**
104-
* @param mixed $array
105-
* @return StrictusArray
106-
*/
10762
public static function nullableArray(mixed $array): StrictusArray
10863
{
10964
return new StrictusArray($array, true);
11065
}
11166

112-
/**
113-
* @param mixed $object
114-
* @param bool $nullable
115-
* @return StrictusObject
116-
*/
11767
public static function object(mixed $object, bool $nullable = false): StrictusObject
11868
{
11969
return new StrictusObject($object, $nullable);
12070
}
12171

122-
/**
123-
* @param mixed $object
124-
* @return StrictusObject
125-
*/
12672
public static function nullableObject(mixed $object): StrictusObject
12773
{
12874
return new StrictusObject($object, true);
12975
}
13076

131-
/**
132-
* @param string $instanceType
133-
* @param mixed $instance
134-
* @param bool $nullable
135-
* @return StrictusInstance
136-
*/
13777
public static function instance(string $instanceType, mixed $instance, bool $nullable = false): StrictusInstance
13878
{
13979
return new StrictusInstance($instanceType, $instance, $nullable);
14080
}
14181

142-
/**
143-
* @param string $instanceType
144-
* @param mixed $instance
145-
* @return StrictusInstance
146-
*/
14782
public static function nullableInstance(string $instanceType, mixed $instance): StrictusInstance
14883
{
14984
return new StrictusInstance($instanceType, $instance, true);

src/Traits/StrictusTyping.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
*/
1313
trait StrictusTyping
1414
{
15-
/**
16-
* @param mixed $value
17-
* @param bool $nullable
18-
*/
1915
public function __construct(private mixed $value, private bool $nullable)
2016
{
2117
if ($this->nullable) {
@@ -25,10 +21,6 @@ public function __construct(private mixed $value, private bool $nullable)
2521
$this->validate($value);
2622
}
2723

28-
/**
29-
* @param mixed $value
30-
* @return mixed
31-
*/
3224
public function __invoke(mixed $value = new StrictusUndefined()): mixed
3325
{
3426
if ($value instanceof StrictusUndefined) {
@@ -42,20 +34,11 @@ public function __invoke(mixed $value = new StrictusUndefined()): mixed
4234
return $this;
4335
}
4436

45-
/**
46-
* @param string $value
47-
* @return mixed
48-
*/
4937
public function __get(string $value): mixed
5038
{
5139
return $this->value;
5240
}
5341

54-
/**
55-
* @param string $name
56-
* @param mixed $value
57-
* @return void
58-
*/
5942
public function __set(string $name, mixed $value): void
6043
{
6144
if ($name !== 'value') {
@@ -67,10 +50,6 @@ public function __set(string $name, mixed $value): void
6750
$this->value = $value;
6851
}
6952

70-
/**
71-
* @param mixed $value
72-
* @return void
73-
*/
7453
private function validate(mixed $value): void
7554
{
7655
if ($value === null && ! $this->nullable) {

src/Types/StrictusInstance.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ final class StrictusInstance implements StrictusTypeInterface
1717

1818
private string $errorMessage;
1919

20-
/**
21-
* @param string $instanceType
22-
* @param mixed $value
23-
* @param bool $nullable
24-
*/
2520
public function __construct(private string $instanceType, private mixed $value, private bool $nullable)
2621
{
27-
$this->errorMessage = 'Expected Instance Of '.$this->instanceType;
22+
$this->errorMessage = 'Expected Instance Of ' . $this->instanceType;
2823

2924
if ($this->nullable) {
3025
$this->errorMessage .= ' Or Null';
@@ -33,10 +28,6 @@ public function __construct(private string $instanceType, private mixed $value,
3328
$this->validate($value);
3429
}
3530

36-
/**
37-
* @param mixed $value
38-
* @return void
39-
*/
4031
private function validate(mixed $value): void
4132
{
4233
if ($value === null && ! $this->nullable) {

tests/Pest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Test Case
@@ -24,9 +26,7 @@
2426
|
2527
*/
2628

27-
expect()->extend('toBeOne', function () {
28-
return $this->toBe(1);
29-
});
29+
expect()->extend('toBeOne', fn () => $this->toBe(1));
3030

3131
/*
3232
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)