Skip to content

Commit c106a55

Browse files
committed
Minor improvements
1 parent f6b0f82 commit c106a55

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/Validator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function builtInTypes()
2323
{
2424
return [
2525
'integer' => 'is_integer',
26-
'float' => 'is_float',
26+
'double' => 'is_double',
2727
'boolean' => 'is_bool',
2828
'string' => 'is_string',
2929
'number' => [$this, 'isNumber'],
@@ -86,10 +86,10 @@ protected function getType($value)
8686
/**
8787
* Add a new type.
8888
*
89-
* @param $type
90-
* @param $definition
89+
* @param string $type
90+
* @param mixed $definition
9191
*/
92-
public function addType($type, $definition)
92+
public function addType(string $type, $definition)
9393
{
9494
if (isset($this->types[$type])) {
9595
throw new \InvalidArgumentException("The type: $type is already exists");
@@ -111,7 +111,7 @@ public function addError($key, $message)
111111
$this->errors[$key] = $message;
112112
}
113113

114-
public function reset()
114+
protected function reset()
115115
{
116116
$this->errors = [];
117117
}

tests/JsonTypeTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class JsonTypeTest extends PHPUnit_Framework_TestCase
1414
{
15-
protected function createJsonType()
15+
protected function createValidator()
1616
{
1717
return new Validator();
1818
}
@@ -23,7 +23,7 @@ public function basicTypes()
2323
['string', 'foobar', true],
2424
['string', 123, false],
2525
['integer', 123, true],
26-
['float', 123.1, true],
26+
['double', 123.1, true],
2727

2828
['number', 123.1, true],
2929
['number', 234, true],
@@ -44,7 +44,7 @@ public function basicTypes()
4444
*/
4545
public function testMatchBasicTypes($type, $data, $result)
4646
{
47-
$json = $this->createJsonType();
47+
$json = $this->createValidator();
4848

4949
$method = $result ? 'assertTrue' : 'assertFalse';
5050

@@ -73,7 +73,7 @@ protected function userData()
7373

7474
public function testMatchCustomType()
7575
{
76-
$json = $this->createJsonType();
76+
$json = $this->createValidator();
7777

7878
$json->addType('user', $this->userType());
7979

@@ -83,7 +83,7 @@ public function testMatchCustomType()
8383

8484
public function testMatchArrayOfCustomType()
8585
{
86-
$json = $this->createJsonType();
86+
$json = $this->createValidator();
8787

8888
$json->addType('user', $this->userType());
8989

@@ -92,7 +92,7 @@ public function testMatchArrayOfCustomType()
9292

9393
public function testAddCustomTypeThroughCallable()
9494
{
95-
$json = $this->createJsonType();
95+
$json = $this->createValidator();
9696

9797
$json->addType('timestamp', function ($value) {
9898
if ((!is_string($value) && !is_numeric($value)) || strtotime($value) === false) {
@@ -174,7 +174,7 @@ public function typeErrorMessages()
174174
*/
175175
public function testErrorMessages($value, $type, $key, $message)
176176
{
177-
$json = $this->createJsonType();
177+
$json = $this->createValidator();
178178

179179
$this->assertFalse($json->matches($value, $type));
180180
$this->assertEquals($message, $json->getErrors()[$key] ?? '');

0 commit comments

Comments
 (0)