Skip to content

Commit d348bd0

Browse files
committed
[+]: Code improvements [+]: filterBy Method, [+]: Update README.md [+]: More tests
1 parent e2a7963 commit d348bd0

File tree

6 files changed

+421
-184
lines changed

6 files changed

+421
-184
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DotArray Change Log
22
=====================
33

4-
1.0.0 December 24, 2018
4+
1.0.0 December 26, 2018
55
-----------------------------
66

77
- Initial release.

README.md

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DotArray
22

3-
Require `PHP >=7.1`
3+
[![Require `PHP >= 7.1`](https://img.shields.io/badge/Require%20PHP-%3E%3D%207.1-brightgreen.svg)](https://github.com/binary-cube/dot-array)
44

55
Accessing PHP Arrays via DOT notation is easy as:
66

@@ -65,6 +65,9 @@ DotArray::create(['config' => ['some.dotted.key' => 'value']])->get('config.{som
6565
// Accessing the last leaf and getting the raw data.
6666
$dot('books.{sci-fi & fantasy}.0.name');
6767
$dot->get('books.{sci-fi & fantasy}.0.name');
68+
69+
// Giving a default value in case the requested key is not found.
70+
$dot->get('key.not.exist', 'not-found-as-string');
6871

6972
// Vanilla PHP.
7073
$dot('books.{sci-fi & fantasy}.0.name');
@@ -137,27 +140,66 @@ DotArray::create(['config' => ['some.dotted.key' => 'value']])->get('config.{som
137140
138141
$books->toArray();
139142
```
143+
144+
- **filterBy**:
145+
- ```php
146+
/*
147+
Allowed comparison operators:
148+
- [ =, ==, eq (equal) ]
149+
- [ ===, i (identical) ]
150+
- [ !=, ne (not equal) ]
151+
- [ !==, ni (not identical) ]
152+
- [ <, lt (less than) ]
153+
- [ >, gr (greater than) ]
154+
- [ <=, lte (less than or equal to) ]
155+
- [ =>, gte (greater than or equal to) ]
156+
- [ in, contains ]
157+
- [ not-in, not-contains ]
158+
- [ between ]
159+
- [ not-between ]
160+
*/
161+
// Example 1.
162+
$books = $dot->get('books.{childre\'s books}')->filterBy('price', 'between', 5, 12);
163+
164+
// Example 2.
165+
$books = $dot->get('books.{childre\'s books}')->filterBy('price', '>', 10);
166+
167+
// Example 3.
168+
$books = $dot->get('books.{childre\'s books}')->filterBy('price', 'in', [8.5, 15.49]);
169+
```
140170
141171
- **where**:
142172
- ```php
143173
/*
144-
Allowed Operations:
145-
=, == ===, !=, !==, <, >, <=, >=,
146-
in, not-in, between, not-between, eq, ne, lt, gt, lte, gte, contains, not-contains
174+
The signature of the `where` call can be:
175+
- where([property, comparisonOperator, ...value])
176+
- where(\Closure) :: The signature of the callable must be: `function ($value, $key)`
177+
178+
Allowed comparison operators:
179+
- [ =, ==, eq (equal) ]
180+
- [ ===, i (identical) ]
181+
- [ !=, ne (not equal) ]
182+
- [ !==, ni (not identical) ]
183+
- [ <, lt (less than) ]
184+
- [ >, gr (greater than) ]
185+
- [ <=, lte (less than or equal to) ]
186+
- [ =>, gte (greater than or equal to) ]
187+
- [ in, contains ]
188+
- [ not-in, not-contains ]
189+
- [ between ]
190+
- [ not-between ]
147191
*/
148192
149-
// Example 1.
150-
$books = $dot->get('books.{childre\'s books}')->where(['between', 'price', 5, 12]);
193+
// Example 1. (using the signature: [property, comparisonOperator, ...value])
194+
$books = $dot->get('books.{childre\'s books}')->where(['price', 'between', 5, 12]);
151195
152-
$books->toArray();
153-
154-
// Example 2.
155-
$books = $dot->get('books.{childre\'s books}')->where(['>', 'price', 10]);
196+
// Example 2. (using the signature: [property, comparisonOperator, ...value])
197+
$books = $dot->get('books.{childre\'s books}')->where(['price', '>', 10]);
156198
157-
// Example 3.
158-
$books = $dot->get('books.{childre\'s books}')->where(['in', 'price', [8.5, 15.49]]);
199+
// Example 3. (using the signature: [property, comparisonOperator, ...value])
200+
$books = $dot->get('books.{childre\'s books}')->where(['price', 'in', [8.5, 15.49]]);
159201
160-
// Example 4.
202+
// Example 4. (using the signature: \Closure)
161203
$books = $dot->get('books.{childre\'s books}')->where(function ($value, $key) {
162204
return $value['name'] === 'Harry Potter and the Order of the Phoenix';
163205
});

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
"require-dev": {
3333
"squizlabs/php_codesniffer": "3.*",
34-
"phpunit/phpunit": "~7.0"
34+
"phpunit/phpunit": "~7.0",
35+
"phpmd/phpmd": "*"
3536
},
3637

3738
"suggest": {

phpmd.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Code Size Rules"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
7+
8+
<description>PHP Mess Detector</description>
9+
10+
<rule ref="rulesets/cleancode.xml">
11+
<exclude name="StaticAccess"/>
12+
<exclude name="BooleanArgumentFlag"/>
13+
</rule>
14+
15+
<rule ref="rulesets/codesize.xml">
16+
<exclude name="TooManyPublicMethods"/>
17+
</rule>
18+
19+
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
20+
<properties>
21+
<property name="maxmethods" value="20"/>
22+
</properties>
23+
</rule>
24+
25+
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
26+
<properties>
27+
<property name="minimum" value="100"/>
28+
</properties>
29+
</rule>
30+
31+
<rule ref="rulesets/controversial.xml">
32+
<exclude name="CamelCaseVariableName"/>
33+
</rule>
34+
35+
<rule ref="rulesets/design.xml"/>
36+
37+
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
38+
<properties>
39+
<property name="minimum" value="15"/>
40+
</properties>
41+
</rule>
42+
43+
<rule ref="rulesets/naming.xml">
44+
<exclude name="ShortVariable"/>
45+
<exclude name="LongVariable"/>
46+
<exclude name="ShortMethodName"/>
47+
</rule>
48+
49+
<rule ref="rulesets/naming.xml/ShortVariable">
50+
<properties>
51+
<property name="minimum" value="2"/>
52+
</properties>
53+
</rule>
54+
55+
<rule ref="rulesets/naming.xml/LongVariable">
56+
<properties>
57+
<property name="maximum" value="30"/>
58+
</properties>
59+
</rule>
60+
61+
<rule ref="rulesets/naming.xml/ShortMethodName">
62+
<properties>
63+
<property name="minimum" value="2"/>
64+
</properties>
65+
</rule>
66+
67+
<rule ref="rulesets/naming.xml/BooleanGetMethodName">
68+
<properties>
69+
<property name="checkParameterizedMethods" value="true"/>
70+
</properties>
71+
</rule>
72+
73+
<rule ref="rulesets/unusedcode.xml"/>
74+
75+
</ruleset>

0 commit comments

Comments
 (0)