Skip to content

Commit 1f0503c

Browse files
committed
Init
0 parents  commit 1f0503c

File tree

14 files changed

+720
-0
lines changed

14 files changed

+720
-0
lines changed

.cs.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setUsingCache(false)
5+
->setRiskyAllowed(true)
6+
//->setCacheFile(__DIR__ . '/.php_cs.cache')
7+
->setRules([
8+
'@PSR1' => true,
9+
'@PSR2' => true,
10+
'@Symfony' => true,
11+
'psr4' => true,
12+
// custom rules
13+
'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], // psr-5
14+
'phpdoc_to_comment' => false,
15+
'array_indentation' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'cast_spaces' => ['space' => 'none'],
18+
'concat_space' => ['spacing' => 'one'],
19+
'compact_nullable_typehint' => true,
20+
'declare_equal_normalize' => ['space' => 'single'],
21+
'increment_style' => ['style' => 'post'],
22+
'list_syntax' => ['syntax' => 'long'],
23+
'no_short_echo_tag' => true,
24+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
25+
'phpdoc_align' => false,
26+
'phpdoc_no_empty_return' => false,
27+
'phpdoc_order' => true, // psr-5
28+
'phpdoc_no_useless_inheritdoc' => false,
29+
'protected_to_private' => false,
30+
'yoda_style' => false,
31+
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
32+
'ordered_imports' => [
33+
'sort_algorithm' => 'alpha',
34+
'imports_order' => ['class', 'const', 'function']
35+
],
36+
])
37+
->setFinder(PhpCsFixer\Finder::create()
38+
->in(__DIR__ . '/src')
39+
->in(__DIR__ . '/tests')
40+
->name('*.php')
41+
->ignoreDotFiles(true)
42+
->ignoreVCS(true));

.gitattributes

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
# Git will always convert line endings to LF on checkout. You should use
3+
# this for files that must keep LF endings, even on Windows.
4+
* text eol=lf
5+
6+
# ------------------------------------------------------------------------------
7+
# All the files and directories that can be excluded from dist,
8+
# we could have a more clean vendor/
9+
#
10+
# So when someone will install that package through with --prefer-dist option,
11+
# all the files and directories listed in .gitattributes file will be excluded.
12+
# This could have a big impact on big deployments and/or testing.
13+
# ------------------------------------------------------------------------------
14+
15+
/tests export-ignore
16+
/build export-ignore
17+
/docs export-ignore
18+
/build.xml export-ignore
19+
/phpunit.xml export-ignore
20+
/.gitattributes export-ignore
21+
/.gitignore export-ignore
22+
/.travis.* export-ignore
23+
/.scrutinizer.* export-ignore
24+
/.editorconfig export-ignore
25+
/.coveralls.* export-ignore
26+
27+
# Define binary file attributes.
28+
# - Do not treat them as text.
29+
# - Include binary diff in patches instead of "binary files differ."
30+
*.pdf binary
31+
*.mo binary
32+
*.gif binary
33+
*.ico binary
34+
*.jpg binary
35+
*.jpeg binary
36+
*.png binary
37+
*.zip binary

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
composer.lock
3+
nbproject/
4+
vendor/
5+
build/

.scrutinizer.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
filter:
2+
paths: ["src/*"]
3+
excluded_paths: ["vendor/*", "tests/*"]
4+
5+
checks:
6+
php:
7+
code_rating: true
8+
duplication: true
9+
10+
tools:
11+
external_code_coverage: false
12+
13+
build:
14+
environment:
15+
php: 7.2
16+
mysql: false
17+
node: false
18+
postgresql: false
19+
mongodb: false
20+
elasticsearch: false
21+
redis: false
22+
memcached: false
23+
neo4j: false
24+
rabbitmq: false
25+
nodes:
26+
analysis:
27+
tests:
28+
override:
29+
- php-scrutinizer-run
30+
dependencies:
31+
before:
32+
- composer self-update
33+
- composer update --no-interaction --prefer-dist --no-progress
34+
tests:
35+
before:
36+
-
37+
command: composer test-coverage
38+
coverage:
39+
file: 'build/logs/clover.xml'
40+
format: 'clover'

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: php
2+
3+
php:
4+
- 7.0
5+
- 7.1
6+
- 7.2
7+
- 7.3
8+
9+
dist: xenial
10+
11+
cache:
12+
directories:
13+
- $HOME/.composer/cache
14+
15+
before_script:
16+
- composer self-update
17+
- composer install --no-interaction --prefer-dist --no-progress
18+
- cd $TRAVIS_BUILD_DIR
19+
20+
script:
21+
- composer check-all

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 odan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# selective/array-reader
2+
3+
A strictly typed array reader for PHP.
4+
5+
[![Latest Version on Packagist](https://img.shields.io/github/release/selective-php/array-reader.svg?style=flat-square)](https://packagist.org/packages/selective/array-reader)
6+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
7+
[![Build Status](https://img.shields.io/travis/selective-php/array-reader/master.svg?style=flat-square)](https://travis-ci.org/selective-php/array-reader)
8+
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/selective-php/array-reader.svg?style=flat-square)](https://scrutinizer-ci.com/g/selective-php/array-reader/code-structure)
9+
[![Quality Score](https://img.shields.io/scrutinizer/quality/g/selective-php/array-reader.svg?style=flat-square)](https://scrutinizer-ci.com/g/selective-php/array-reader/?branch=master)
10+
[![Total Downloads](https://img.shields.io/packagist/dt/selective/array-reader.svg?style=flat-square)](https://packagist.org/packages/selective/array-reader/stats)
11+
12+
13+
## Requirements
14+
15+
* PHP 7.0+
16+
17+
## Installation
18+
19+
```bash
20+
composer require selective/array-reader
21+
```
22+
23+
## Usage
24+
25+
You can use the `ArrayReader` to read single values from a multidimensional
26+
array by passing the path to one of the `get{type}()` and `find{type}()` methods.
27+
28+
Each `get*() / find*()` method takes a default value as second argument.
29+
If the path cannot be found in the original array, the default is used as return value.
30+
31+
A `get*()` method returns only the declared return type.
32+
If the default value is not given and the element cannot be found, an exception is thrown.
33+
34+
A `find*()` method returns only the declared return type or `null`.
35+
No exception is thrown if the element cannot be found.
36+
37+
```php
38+
<?php
39+
40+
use Selective\ArrayReader\ArrayReader;
41+
42+
$arrayReader = new ArrayReader([
43+
'key1' => [
44+
'key2' => [
45+
'key3' => 'value1',
46+
]
47+
]
48+
]);
49+
50+
// Output: value1
51+
echo $arrayReader->getString('key1.key2.key3');
52+
```
53+
54+
## Similar libraries
55+
56+
* https://github.com/codeliner/array-reader
57+
58+
## License
59+
60+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "selective/array-reader",
3+
"type": "library",
4+
"description": "A strictly typed array reader",
5+
"keywords": [
6+
"array",
7+
"reader",
8+
"strict",
9+
"strictly",
10+
"typed",
11+
"strong"
12+
],
13+
"homepage": "https://github.com/selective-php/array-reader",
14+
"license": "MIT",
15+
"require": {
16+
"php": "^7.0",
17+
"cakephp/chronos": "^1.2"
18+
},
19+
"require-dev": {
20+
"overtrue/phplint": "^1.1",
21+
"phpstan/phpstan-shim": "^0.11",
22+
"phpunit/phpunit": "^7",
23+
"squizlabs/php_codesniffer": "^3.4"
24+
},
25+
"scripts": {
26+
"test": "phpunit --configuration phpunit.xml",
27+
"test-coverage": "phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml --coverage-html build/coverage",
28+
"check-style": "phpcs --standard=phpcs.xml",
29+
"fix-style": "phpcbf --standard=phpcs.xml",
30+
"phpstan": "phpstan analyse src tests --level=max -c phpstan.neon --no-progress",
31+
"lint": "phplint ./ --exclude=vendor --no-interaction --no-cache",
32+
"install-cs": "php -r \"@mkdir('build'); copy('https://cs.symfony.com/download/php-cs-fixer-v2.phar', 'build/php-cs-fixer-v2.phar');\"",
33+
"fix-cs": "php build/php-cs-fixer-v2.phar fix --config=.cs.php",
34+
"check-cs": "php build/php-cs-fixer-v2.phar fix --dry-run --format=txt --verbose --diff --diff-format=udiff --config=.cs.php",
35+
"check-all": [
36+
"@lint",
37+
"@check-style",
38+
"@phpstan",
39+
"@test-coverage"
40+
]
41+
},
42+
"autoload": {
43+
"psr-4": {
44+
"Selective\\ArrayReader\\": "src"
45+
}
46+
},
47+
"autoload-dev": {
48+
"psr-4": {
49+
"Selective\\ArrayReader\\Test\\": "tests"
50+
}
51+
},
52+
"config": {
53+
"sort-packages": true
54+
}
55+
}

phpcs.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Coding Standard">
3+
<arg name="basepath" value="."/>
4+
<arg name="colors"/>
5+
<arg value="sp"/>
6+
7+
<config name="ignore_warnings_on_exit" value="1"/>
8+
9+
<file>./src</file>
10+
<file>./tests</file>
11+
12+
<rule ref="PSR2"></rule>
13+
<rule ref="PSR12"></rule>
14+
15+
<rule ref="Squiz.Commenting.ClassComment">
16+
<exclude name="Squiz.Commenting.ClassComment.TagNotAllowed"/>
17+
<type>warning</type>
18+
<exclude-pattern>*/tests/</exclude-pattern>
19+
</rule>
20+
<rule ref="Squiz.Commenting.ClassComment.Missing">
21+
<type>warning</type>
22+
</rule>
23+
<rule ref="Squiz.Commenting.FunctionComment.Missing">
24+
<type>warning</type>
25+
<exclude-pattern>*/config/</exclude-pattern>
26+
</rule>
27+
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
28+
<type>warning</type>
29+
</rule>
30+
<rule ref="Squiz.Commenting.FunctionComment.MissingParamComment">
31+
<type>warning</type>
32+
</rule>
33+
<rule ref="Squiz.Commenting.FunctionComment.ParamCommentNotCapital">
34+
<type>warning</type>
35+
</rule>
36+
37+
<rule ref="Generic.Metrics.CyclomaticComplexity">
38+
<properties>
39+
<property name="absoluteComplexity" value="50"/>
40+
</properties>
41+
</rule>
42+
<rule ref="Generic.Metrics.NestingLevel">
43+
<properties>
44+
<property name="nestingLevel" value="2"/>
45+
<property name="absoluteNestingLevel" value="4"/>
46+
</properties>
47+
</rule>
48+
</ruleset>

phpstan.neon

Whitespace-only changes.

0 commit comments

Comments
 (0)