Skip to content

Commit 07a8835

Browse files
Only support PHP 7.0 and above
1 parent 3fbd874 commit 07a8835

File tree

10 files changed

+148
-146
lines changed

10 files changed

+148
-146
lines changed

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
language: php
22

33
php:
4-
- 5.3
5-
- 5.4
6-
- 5.5
7-
- 5.6
4+
- 7.0
5+
- 7.1
6+
- 7.2
87

98
before_script:
109
- wget -nc http://getcomposer.org/composer.phar
11-
- php composer.phar install --dev
10+
- php composer.phar install
1211

13-
script: phpunit --coverage-text
12+
script: ./vendor/bin/phpunit --coverage-text

README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Given a deep data structure, access data by dot notation.
77
Requirements
88
------------
99

10-
* PHP (5.3+)
10+
* PHP (7.0+)
11+
12+
> For PHP (5.3+) please reffer to version `1.0`.
1113
1214

1315
Usage
@@ -23,15 +25,15 @@ $data = new Data;
2325
$data->set('a.b.c', 'C');
2426
$data->set('a.b.d', 'D1');
2527
$data->append('a.b.d', 'D2');
26-
$data->set('a.b.e', array('E0', 'E1', 'E2'));
28+
$data->set('a.b.e', ['E0', 'E1', 'E2']);
2729

2830
// C
2931
$data->get('a.b.c');
3032

31-
// array('D1', 'D2')
33+
// ['D1', 'D2']
3234
$data->get('a.b.d');
3335

34-
// array('E0', 'E1', 'E2')
36+
// ['E0', 'E1', 'E2']
3537
$data->get('a.b.e');
3638

3739
// true
@@ -46,32 +48,32 @@ A more concrete example:
4648
```php
4749
use Dflydev\DotAccessData\Data;
4850

49-
$data = new Data(array(
50-
'hosts' => array(
51-
'hewey' => array(
51+
$data = new Data([
52+
'hosts' => [
53+
'hewey' => [
5254
'username' => 'hman',
5355
'password' => 'HPASS',
54-
'roles' => array('web'),
55-
),
56-
'dewey' => array(
56+
'roles' => ['web'],
57+
],
58+
'dewey' => [
5759
'username' => 'dman',
5860
'password' => 'D---S',
59-
'roles' => array('web', 'db'),
60-
'nick' => 'dewey dman'
61-
),
62-
'lewey' => array(
61+
'roles' => ['web', 'db'],
62+
'nick' => 'dewey dman',
63+
],
64+
'lewey' => [
6365
'username' => 'lman',
6466
'password' => 'LP@$$',
65-
'roles' => array('db'),
66-
),
67-
)
68-
));
67+
'roles' => ['db'],
68+
],
69+
],
70+
]);
6971

7072
// hman
7173
$username = $data->get('hosts.hewey.username');
7274
// HPASS
7375
$password = $data->get('hosts.hewey.password');
74-
// array('web')
76+
// ['web']
7577
$roles = $data->get('hosts.hewey.roles');
7678
// dewey dman
7779
$nick = $data->get('hosts.dewey.nick');
@@ -84,7 +86,7 @@ $dewey = $data->getData('hosts.dewey');
8486
$username = $dewey->get('username');
8587
// D---S
8688
$password = $dewey->get('password');
87-
// array('web', 'db')
89+
// ['web', 'db']
8890
$roles = $dewey->get('roles');
8991

9092
// No more lewey
@@ -93,11 +95,11 @@ $data->remove('hosts.lewey');
9395
// Add DB to hewey's roles
9496
$data->append('hosts.hewey.roles', 'db');
9597

96-
$data->set('hosts.april', array(
98+
$data->set('hosts.april', [
9799
'username' => 'aman',
98100
'password' => '@---S',
99-
'roles' => array('web'),
100-
));
101+
'roles' => ['web'],
102+
]);
101103

102104
// Check if a key exists (true to this case)
103105
$hasKey = $data->has('hosts.dewey.username');

composer.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@
2323
}
2424
],
2525
"require": {
26-
"php": ">=5.3.2"
26+
"php": "^7.0"
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "^6.0"
2730
},
2831
"autoload": {
29-
"psr-0": {
30-
"Dflydev\\DotAccessData": "src"
32+
"psr-4": {
33+
"Dflydev\\DotAccessData\\": "src/"
34+
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"Dflydev\\DotAccessData\\": "tests/"
3139
}
3240
},
3341
"extra": {
3442
"branch-alias": {
35-
"dev-master": "1.0-dev"
43+
"dev-master": "2.0-dev"
3644
}
3745
}
3846
}

phpunit.xml.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" bootstrap="tests/bootstrap.php">
2+
<phpunit colors="true">
33
<testsuites>
44
<testsuite name="Dot Access Data Test Suite">
5-
<directory>./tests/Dflydev/DotAccessData</directory>
5+
<directory>./tests</directory>
66
</testsuite>
77
</testsuites>
88

99
<filter>
1010
<whitelist>
11-
<directory>./src/Dflydev/DotAccessData/</directory>
11+
<directory>./src</directory>
1212
</whitelist>
1313
</filter>
1414
</phpunit>
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Dflydev\DotAccessData;
1313

14+
use RuntimeException;
15+
1416
class Data implements DataInterface
1517
{
1618
/**
@@ -27,7 +29,7 @@ class Data implements DataInterface
2729
*/
2830
public function __construct(array $data = null)
2931
{
30-
$this->data = $data ?: array();
32+
$this->data = $data ?: [];
3133
}
3234

3335
/**
@@ -36,20 +38,20 @@ public function __construct(array $data = null)
3638
public function append($key, $value = null)
3739
{
3840
if (0 == strlen($key)) {
39-
throw new \RuntimeException("Key cannot be an empty string");
41+
throw new RuntimeException("Key cannot be an empty string");
4042
}
4143

4244
$currentValue =& $this->data;
4345
$keyPath = explode('.', $key);
4446

4547
if (1 == count($keyPath)) {
4648
if (!isset($currentValue[$key])) {
47-
$currentValue[$key] = array();
49+
$currentValue[$key] = [];
4850
}
4951
if (!is_array($currentValue[$key])) {
5052
// Promote this key to an array.
5153
// TODO: Is this really what we want to do?
52-
$currentValue[$key] = array($currentValue[$key]);
54+
$currentValue[$key] = [$currentValue[$key]];
5355
}
5456
$currentValue[$key][] = $value;
5557

@@ -60,16 +62,16 @@ public function append($key, $value = null)
6062
for ( $i = 0; $i < count($keyPath); $i++ ) {
6163
$currentKey =& $keyPath[$i];
6264
if ( ! isset($currentValue[$currentKey]) ) {
63-
$currentValue[$currentKey] = array();
65+
$currentValue[$currentKey] = [];
6466
}
6567
$currentValue =& $currentValue[$currentKey];
6668
}
6769

6870
if (!isset($currentValue[$endKey])) {
69-
$currentValue[$endKey] = array();
71+
$currentValue[$endKey] = [];
7072
}
7173
if (!is_array($currentValue[$endKey])) {
72-
$currentValue[$endKey] = array($currentValue[$endKey]);
74+
$currentValue[$endKey] = [$currentValue[$endKey]];
7375
}
7476
// Promote this key to an array.
7577
// TODO: Is this really what we want to do?
@@ -82,7 +84,7 @@ public function append($key, $value = null)
8284
public function set($key, $value = null)
8385
{
8486
if (0 == strlen($key)) {
85-
throw new \RuntimeException("Key cannot be an empty string");
87+
throw new RuntimeException("Key cannot be an empty string");
8688
}
8789

8890
$currentValue =& $this->data;
@@ -98,10 +100,10 @@ public function set($key, $value = null)
98100
for ( $i = 0; $i < count($keyPath); $i++ ) {
99101
$currentKey =& $keyPath[$i];
100102
if (!isset($currentValue[$currentKey])) {
101-
$currentValue[$currentKey] = array();
103+
$currentValue[$currentKey] = [];
102104
}
103105
if (!is_array($currentValue[$currentKey])) {
104-
throw new \RuntimeException("Key path at $currentKey of $key cannot be indexed into (is not an array)");
106+
throw new RuntimeException("Key path at $currentKey of $key cannot be indexed into (is not an array)");
105107
}
106108
$currentValue =& $currentValue[$currentKey];
107109
}
@@ -114,7 +116,7 @@ public function set($key, $value = null)
114116
public function remove($key)
115117
{
116118
if (0 == strlen($key)) {
117-
throw new \RuntimeException("Key cannot be an empty string");
119+
throw new RuntimeException("Key cannot be an empty string");
118120
}
119121

120122
$currentValue =& $this->data;
@@ -191,7 +193,7 @@ public function getData($key)
191193
return new Data($value);
192194
}
193195

194-
throw new \RuntimeException("Value at '$key' could not be represented as a DataInterface");
196+
throw new RuntimeException("Value at '$key' could not be represented as a DataInterface");
195197
}
196198

197199
/**

src/Dflydev/DotAccessData/DataInterface.php renamed to src/DataInterface.php

File renamed without changes.

0 commit comments

Comments
 (0)