Skip to content

Commit 7fcca06

Browse files
Merge pull request #1 from WebdevCave/analysis-54J2lY
Apply fixes from StyleCI
2 parents b83f8c0 + 7b2a117 commit 7fcca06

12 files changed

+54
-51
lines changed

src/Schemas/ArraySchema.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ public function __construct(
1616

1717
/**
1818
* @inheritDoc
19+
*
1920
* @throws Exception
2021
*/
2122
protected function validateSchema(mixed $value): void
2223
{
2324
if (!is_array($value)) {
24-
$this->error($this->customMessages['type'] ?? "Provided value must be an array");
25+
$this->error($this->customMessages['type'] ?? 'Provided value must be an array');
26+
2527
return;
2628
}
2729

src/Schemas/BaseSchema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function optional(): static
5858
return $this;
5959
}
6060

61-
public function refine(callable $callback, $customMessage = "Custom validation error"): static
61+
public function refine(callable $callback, $customMessage = 'Custom validation error'): static
6262
{
6363
$this->customMessages['refine'] = $customMessage;
6464
$this->callback = $callback(...);
@@ -100,7 +100,7 @@ public function validate(mixed $value): bool
100100
*
101101
* @return void
102102
*/
103-
protected final function error(string $message): void
103+
final protected function error(string $message): void
104104
{
105105
$this->errorMessages[] = $message;
106106
}
@@ -110,7 +110,7 @@ protected final function error(string $message): void
110110
*
111111
* @return void
112112
*/
113-
protected final function setErrorMessages(array $errors): void
113+
final protected function setErrorMessages(array $errors): void
114114
{
115115
$this->errorMessages = $errors;
116116
}

src/Schemas/NumericSchema.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NumericSchema extends BaseSchema
1717
/**
1818
* @return $this
1919
*/
20-
public function integer(string $customMessage = "Value must be an integer"): static
20+
public function integer(string $customMessage = 'Value must be an integer'): static
2121
{
2222
$this->integerOnly = true;
2323
$this->customMessages['integerOnly'] = $customMessage;
@@ -28,7 +28,7 @@ public function integer(string $customMessage = "Value must be an integer"): sta
2828
/**
2929
* @return $this
3030
*/
31-
public function float(string $customMessage = "Value must be a float"): static
31+
public function float(string $customMessage = 'Value must be a float'): static
3232
{
3333
$this->floatOnly = true;
3434
$this->customMessages['floatOnly'] = $customMessage;
@@ -39,7 +39,7 @@ public function float(string $customMessage = "Value must be a float"): static
3939
/**
4040
* @return $this
4141
*/
42-
public function positive(string $customMessage = "Value must be positive"): static
42+
public function positive(string $customMessage = 'Value must be positive'): static
4343
{
4444
$this->positiveOnly = true;
4545
$this->customMessages['positiveOnly'] = $customMessage;
@@ -53,7 +53,7 @@ public function positive(string $customMessage = "Value must be positive"): stat
5353
protected function validateSchema(mixed $value): void
5454
{
5555
if (!is_numeric($value)) {
56-
$this->error($this->customMessages['type'] ?? "Value must be a number");
56+
$this->error($this->customMessages['type'] ?? 'Value must be a number');
5757
}
5858

5959
if (!is_null($this->min) && $value < $this->min) {

src/Schemas/ObjectSchema.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class ObjectSchema extends ArraySchema
99
protected function validateSchema(mixed $value): void
1010
{
1111
if (!is_object($value)) {
12-
$this->error($this->customMessages['type'] ?? "Provided value must be an object");
12+
$this->error($this->customMessages['type'] ?? 'Provided value must be an object');
13+
1314
return;
1415
}
1516

src/Schemas/StringSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class StringSchema extends BaseSchema
1919
protected function validateSchema(mixed $value): void
2020
{
2121
if (!is_string($value)) {
22-
$this->error($this->customMessages['type'] ?? "Value must be a string");
22+
$this->error($this->customMessages['type'] ?? 'Value must be a string');
2323
}
2424

2525
if (!is_null($this->min)) {

src/Validator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Webdevcave\SchemaValidator;
44

55
use Webdevcave\SchemaValidator\Schemas\ArraySchema;
6-
use Webdevcave\SchemaValidator\Schemas\BaseSchema;
76
use Webdevcave\SchemaValidator\Schemas\NumericSchema;
87
use Webdevcave\SchemaValidator\Schemas\ObjectSchema;
98
use Webdevcave\SchemaValidator\Schemas\StringSchema;

tests/Schemas/ArraySchemaTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ public function testTypeCheck(): void
2222
{
2323
$schema = Validator::array();
2424

25-
$this->assertFalse($schema->validate(1), "Array schema should not validate integers");
26-
$this->assertFalse($schema->validate(1.1), "Array schema should not validate floats");
27-
$this->assertFalse($schema->validate('str'), "Array schema should not validate strings");
28-
$this->assertFalse($schema->validate(new stdClass()), "Array schema should not validate objects");
25+
$this->assertFalse($schema->validate(1), 'Array schema should not validate integers');
26+
$this->assertFalse($schema->validate(1.1), 'Array schema should not validate floats');
27+
$this->assertFalse($schema->validate('str'), 'Array schema should not validate strings');
28+
$this->assertFalse($schema->validate(new stdClass()), 'Array schema should not validate objects');
2929

30-
$this->assertTrue($schema->validate([1, 2, 3]), "Array schema should validate arrays");
30+
$this->assertTrue($schema->validate([1, 2, 3]), 'Array schema should validate arrays');
3131
}
3232

3333
public function testDataValidation(): void
3434
{
3535
$positiveIntCheckMessage = 'must be positive';
36-
$schema = Validator::array(['name' => Validator::string()->min(3), 'age' => Validator::numeric()->integer()->positive($positiveIntCheckMessage),]);
36+
$schema = Validator::array(['name' => Validator::string()->min(3), 'age' => Validator::numeric()->integer()->positive($positiveIntCheckMessage)]);
3737

38-
$validData = ['name' => 'Carlos', 'age' => 35,];
39-
$this->assertTrue($schema->validate($validData), "Should return true when dataset is valid");
38+
$validData = ['name' => 'Carlos', 'age' => 35];
39+
$this->assertTrue($schema->validate($validData), 'Should return true when dataset is valid');
4040

41-
$invalidData = ['name' => 'John', 'age' => -10,];
42-
$this->assertFalse($schema->validate($invalidData), "Should return false when dataset is not valid");
41+
$invalidData = ['name' => 'John', 'age' => -10];
42+
$this->assertFalse($schema->validate($invalidData), 'Should return false when dataset is not valid');
4343
$this->assertEquals(['age' => [$positiveIntCheckMessage]], $schema->errorMessages(), 'Error messages doesn\'t match');
4444
}
4545

@@ -49,10 +49,10 @@ public function testWildcardIndexValidation()
4949
$schema = Validator::array(['*' => Validator::numeric()->integer($errorMessage)]);
5050

5151
$validData = [1, 2, 3];
52-
$this->assertTrue($schema->validate($validData), "Error evaluating wildcard index with valid data");
52+
$this->assertTrue($schema->validate($validData), 'Error evaluating wildcard index with valid data');
5353

5454
$invalidData = [null];
55-
$this->assertFalse($schema->validate($invalidData), "Error evaluating wildcard index with invalid data");
55+
$this->assertFalse($schema->validate($invalidData), 'Error evaluating wildcard index with invalid data');
5656
}
5757

5858
public function testOptionalCheckShouldPassOnEmptyArray(): void
@@ -74,6 +74,6 @@ public function testDoubleRuleValidation(): void
7474
$data = [
7575
'name' => str_repeat('a', 10),
7676
];
77-
$this->assertTrue($schema->validate($data), "Array schema should accept double rule");
77+
$this->assertTrue($schema->validate($data), 'Array schema should accept double rule');
7878
}
7979
}

tests/Schemas/BaseSchemaTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function testSetGetRule(): void
4343

4444
$this->schema->equals($value);
4545
$this->assertEquals(
46-
$value, $this->schema->equals(),
46+
$value,
47+
$this->schema->equals(),
4748
'Schema should be able to set and get a rule value'
4849
);
4950
}

tests/Schemas/NumericSchemaTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,57 @@ public function testMinValue(): void
1919
$schema = new NumericSchema();
2020
$schema->min(10);
2121

22-
$this->assertTrue($schema->validate(10), "Failed asserting equals than minimum value");
23-
$this->assertTrue($schema->validate(11), "Failed asserting number greater than minimum value");
24-
$this->assertFalse($schema->validate(9), "Failed asserting number lower than minimum value");
22+
$this->assertTrue($schema->validate(10), 'Failed asserting equals than minimum value');
23+
$this->assertTrue($schema->validate(11), 'Failed asserting number greater than minimum value');
24+
$this->assertFalse($schema->validate(9), 'Failed asserting number lower than minimum value');
2525
}
2626

2727
public function testMaxValue(): void
2828
{
2929
$schema = new NumericSchema();
3030
$schema->max(10);
3131

32-
$this->assertTrue($schema->validate(10), "Failed asserting equals than maximum value");
33-
$this->assertFalse($schema->validate(11), "Failed asserting number greater than maximum value");
34-
$this->assertTrue($schema->validate(9), "Failed asserting number lower than maximum value");
32+
$this->assertTrue($schema->validate(10), 'Failed asserting equals than maximum value');
33+
$this->assertFalse($schema->validate(11), 'Failed asserting number greater than maximum value');
34+
$this->assertTrue($schema->validate(9), 'Failed asserting number lower than maximum value');
3535
}
3636

3737
public function testRequirePositive(): void
3838
{
3939
$schema = new NumericSchema();
4040
$schema->positive();
4141

42-
$this->assertTrue($schema->validate(1), "Failed asserting positive value");
43-
$this->assertFalse($schema->validate(-1), "Failed asserting negative value (positive required)");
42+
$this->assertTrue($schema->validate(1), 'Failed asserting positive value');
43+
$this->assertFalse($schema->validate(-1), 'Failed asserting negative value (positive required)');
4444
}
4545

4646
public function testTypeValidation(): void
4747
{
4848
$schema = new NumericSchema();
4949

50-
$this->assertFalse($schema->validate('str'), "Numeric schema should not validate strings");
51-
$this->assertFalse($schema->validate(new stdClass()), "Numeric schema should not validate objects");
52-
$this->assertFalse($schema->validate([1,2,3]), "Numeric schema should validate arrays");
50+
$this->assertFalse($schema->validate('str'), 'Numeric schema should not validate strings');
51+
$this->assertFalse($schema->validate(new stdClass()), 'Numeric schema should not validate objects');
52+
$this->assertFalse($schema->validate([1, 2, 3]), 'Numeric schema should validate arrays');
5353

54-
$this->assertTrue($schema->validate(1), "Numeric schema should validate integers");
55-
$this->assertTrue($schema->validate(1.1), "Numeric schema should validate floats");
54+
$this->assertTrue($schema->validate(1), 'Numeric schema should validate integers');
55+
$this->assertTrue($schema->validate(1.1), 'Numeric schema should validate floats');
5656
}
5757

5858
public function testExclusiveIntegerValidation(): void
5959
{
6060
$schema = new NumericSchema();
6161
$schema->integer();
6262

63-
$this->assertTrue($schema->validate(1), "Numeric schema should validate integers (int only)");
64-
$this->assertFalse($schema->validate(1.1), "Numeric schema should not validate floats (int only)");
63+
$this->assertTrue($schema->validate(1), 'Numeric schema should validate integers (int only)');
64+
$this->assertFalse($schema->validate(1.1), 'Numeric schema should not validate floats (int only)');
6565
}
6666

6767
public function testExclusiveFloatValidation(): void
6868
{
6969
$schema = new NumericSchema();
7070
$schema->float();
7171

72-
$this->assertFalse($schema->validate(1), "Numeric schema should not validate integers (floats only)");
73-
$this->assertTrue($schema->validate(1.1), "Numeric schema should validate floats (floats only)");
72+
$this->assertFalse($schema->validate(1), 'Numeric schema should not validate integers (floats only)');
73+
$this->assertTrue($schema->validate(1.1), 'Numeric schema should validate floats (floats only)');
7474
}
7575
}

tests/Schemas/ObjectSchemaTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace Webdevcave\SchemaValidator\Tests\Schemas;
44

55
use PHPUnit\Framework\Attributes\CoversClass;
6+
use PHPUnit\Framework\TestCase;
67
use stdClass;
78
use Webdevcave\SchemaValidator\Schemas\ArraySchema;
89
use Webdevcave\SchemaValidator\Schemas\BaseSchema;
910
use Webdevcave\SchemaValidator\Schemas\ObjectSchema;
10-
use PHPUnit\Framework\TestCase;
1111
use Webdevcave\SchemaValidator\Validator;
1212

1313
#[CoversClass(ObjectSchema::class)]
@@ -20,11 +20,11 @@ public function testTypeCheck(): void
2020
{
2121
$schema = Validator::object();
2222

23-
$this->assertFalse($schema->validate(1), "Array schema should not validate integers");
24-
$this->assertFalse($schema->validate(1.1), "Array schema should not validate floats");
25-
$this->assertFalse($schema->validate('str'), "Array schema should not validate strings");
26-
$this->assertFalse($schema->validate([1, 2, 3]), "Array schema should not validate arrays");
23+
$this->assertFalse($schema->validate(1), 'Array schema should not validate integers');
24+
$this->assertFalse($schema->validate(1.1), 'Array schema should not validate floats');
25+
$this->assertFalse($schema->validate('str'), 'Array schema should not validate strings');
26+
$this->assertFalse($schema->validate([1, 2, 3]), 'Array schema should not validate arrays');
2727

28-
$this->assertTrue($schema->validate(new stdClass()), "Array schema should validate object");
28+
$this->assertTrue($schema->validate(new stdClass()), 'Array schema should validate object');
2929
}
3030
}

0 commit comments

Comments
 (0)