Skip to content

Commit 9a02afa

Browse files
committed
1.0.0
- Fixed bug when validating either a false or null value - Requires PHP 7.1+
1 parent bdb6bcf commit 9a02afa

11 files changed

+54
-43
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: php
22

33
php:
4-
- 7.0
54
- 7.1
5+
- 7.2
66

77
before_script:
88
- composer install

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Status](https://travis-ci.org/nonamephp/php7-common.svg?branch=master)](https://
44
php7-common
55
=============
66

7-
A collection of common libraries for PHP 7.
7+
A collection of common libraries for PHP 7.1+.
88

99
## Installation
1010

@@ -14,12 +14,12 @@ Use Composer to install `php7-common` into your project.
1414

1515
## Included Libraries
1616

17-
* `Noname\Common\Arr`
18-
* `Noname\Common\Collection`
19-
* `Noname\Common\Str`
20-
* `Noname\Common\Validator`
17+
* `Noname\Arr`
18+
* `Noname\Collection`
19+
* `Noname\Str`
20+
* `Noname\Validator`
2121

22-
### `\Noname\Common\Arr`
22+
### `\Noname\Arr`
2323

2424
A helper library for working with arrays.
2525

@@ -39,7 +39,7 @@ Recursively assign the callable's return value to each array item. Array keys ar
3939

4040
```php
4141
<?php
42-
use Noname\Common\Arr;
42+
use Noname\Arr;
4343

4444
$values = [1, 2, 3, 4, 5];
4545

@@ -49,7 +49,7 @@ $values_doubled = Arr::each($values, function ($value) {
4949
});
5050
```
5151

52-
### `\Noname\Common\Collection`
52+
### `\Noname\Collection`
5353

5454
Create a `Collection` with an associative array to provide helpful methods for working with your data.
5555

@@ -59,7 +59,7 @@ Create a `Collection` with an associative array to provide helpful methods for w
5959

6060
```php
6161
<?php
62-
use Noname\Common\Collection;
62+
use Noname\Collection;
6363

6464
$userData = [
6565
'user_id' => 100,
@@ -148,7 +148,7 @@ Returns collection as JSON.
148148

149149
Flatten all of the items in the collection using dot (.) notation.
150150

151-
### `\Noname\Common\Str`
151+
### `\Noname\Str`
152152

153153
A helper library for working with strings.
154154

@@ -174,15 +174,15 @@ Checks if string contains another string. By default this method is case-sensiti
174174

175175
Splits a string into an array containing each character.
176176

177-
### \Noname\Common\Validator
177+
### \Noname\Validator
178178

179179
Use `Validator` to validate your data based on a set of rules.
180180

181181
##### Usage Example
182182

183183
```php
184184
<?php
185-
use Noname\Common\Validator;
185+
use Noname\Validator;
186186

187187
// Data to be validated
188188
$data = [
@@ -250,7 +250,7 @@ Add a custom validator type. The following example will add a type of `equals_2`
250250

251251
```php
252252
<?php
253-
use Noname\Common\Validator;
253+
use Noname\Validator;
254254

255255
// Data to be validated
256256
$values = ['a' => 3];
@@ -330,7 +330,7 @@ This method is useful when validating a single value.
330330

331331
```php
332332
<?php
333-
use Noname\Common\Validator;
333+
use Noname\Validator;
334334

335335
Validator::is('string', 'Hello world!'); // @return true
336336
Validator::is('integer', 'Hello world!'); // @return false
@@ -342,7 +342,7 @@ Similar to `is()`, except type is passed in the method name.
342342

343343
```php
344344
<?php
345-
use Noname\Common\Validator;
345+
use Noname\Validator;
346346

347347
Validator::isString('Hello world!'); // @return true
348348
Validator::isInteger('Hello world!'); // @return false

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nonamephp/php7-common",
33
"description": "A collection of common PHP 7 libraries",
4-
"version": "0.3.13",
4+
"version": "1.0.0",
55
"license": "MIT",
66
"authors": [
77
{
@@ -16,20 +16,20 @@
1616
"keywords": ["noname", "php7", "common", "collection", "validator", "array", "string"],
1717
"homepage": "https://github.com/nonamephp/php7-common",
1818
"require": {
19-
"php": ">=7.0"
19+
"php": ">=7.1"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "~4.0",
23-
"squizlabs/php_codesniffer": "2.*"
22+
"phpunit/phpunit": "^7.0",
23+
"squizlabs/php_codesniffer": "3.2.*"
2424
},
2525
"autoload": {
2626
"psr-4": {
27-
"Noname\\Common\\": "src"
27+
"Noname\\": "src"
2828
}
2929
},
3030
"autoload-dev": {
3131
"psr-4": {
32-
"Noname\\Common\\": "tests"
32+
"Noname\\": "tests"
3333
}
3434
},
3535
"scripts": {

src/Arr.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php declare(strict_types = 1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

44
/**
55
* Class Arr
66
*
7-
* @package Noname\Common
7+
* @package Noname
88
*/
99
class Arr
1010
{

src/Collection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php declare(strict_types = 1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

44
use ArrayAccess;
55
use Countable;
@@ -10,7 +10,7 @@
1010
/**
1111
* Collection
1212
*
13-
* @package Noname\Common
13+
* @package Noname
1414
*/
1515
class Collection implements Countable, ArrayAccess, IteratorAggregate, Serializable, JsonSerializable
1616
{
@@ -164,7 +164,8 @@ public function values(): array
164164
*/
165165
public function has($key): bool
166166
{
167-
return isset($this->items[$key]);
167+
$hasKey = array_key_exists($key, $this->items);
168+
return $hasKey || isset($this->items[$key]);
168169
}
169170

170171
/**

src/Str.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php declare(strict_types = 1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

44
/**
55
* Class Str
66
*
7-
* @package Noname\Common
7+
* @package Noname
88
*/
99
class Str
1010
{

src/Validator.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php declare(strict_types = 1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

44
/**
55
* Validator
66
*
7-
* @package Noname\Common
8-
* @since 0.2.0
7+
* @package Noname
98
*
109
* @method static bool is(string $type, mixed $value, array $rule = []) Checks if value passes as type
1110
* @method static bool isAny(mixed $value, array $rule = []) Always returns true
@@ -400,8 +399,11 @@ public function validate(): bool
400399
// Add key/name to $rule
401400
$rule['name'] = $name;
402401

403-
// Check if value exists in dataset
404-
if ($value = $this->values->get($rule['name'], false)) {
402+
// Check if value exists
403+
if ($this->values->has($rule['name'])) {
404+
// Set value
405+
$value = $this->values->get($rule['name']);
406+
405407
// Validate type
406408
if (!$this->validateType($rule['type'], $value, $rule)) {
407409
// Value didn't pass validation; Process next rule.

tests/ArrTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php declare(strict_types=1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

4-
class ArrTest extends \PHPUnit_Framework_TestCase
4+
use PHPUnit\Framework\TestCase;
5+
6+
class ArrTest extends TestCase
57
{
68
/**
79
* @covers Arr::flatten, Arr::dot

tests/CollectionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php declare(strict_types=1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

4-
class CollectionTest extends \PHPUnit_Framework_TestCase
4+
use PHPUnit\Framework\TestCase;
5+
6+
class CollectionTest extends TestCase
57
{
68
protected $collection;
79

tests/StrTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<?php declare(strict_types = 1);
2-
namespace Noname\Common;
1+
<?php declare(strict_types=1);
2+
namespace Noname;
33

4-
class StrTest extends \PHPUnit_Framework_TestCase
4+
use PHPUnit\Framework\TestCase;
5+
6+
class StrTest extends TestCase
57
{
68
/**
79
* @covers Str::testStartsWith

tests/ValidatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php declare(strict_types=1);
2-
namespace Noname\Common;
2+
namespace Noname;
33

4-
class ValidatorTest extends \PHPUnit_Framework_TestCase
4+
use PHPUnit\Framework\TestCase;
5+
6+
class ValidatorTest extends TestCase
57
{
68
protected $dir;
79
protected $file;

0 commit comments

Comments
 (0)