Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/tests export-ignore
.coveralls.yml export-ignore
.docheader export-ignore
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
language: php

php:
- 5.4
- 7.1
- 7.2


before_script:
- composer self-update
- composer --dev install

script:
- php ./vendor/bin/phpunit -c ./tests/.
- php ./vendor/bin/phpunit

15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@
"util"
],
"require": {
"php": ">=5.3.3"
"php": ">=7.1"
},
"require-dev" : {
"phpunit/phpunit": "3.7.*"
"phpunit/phpunit": ">=7.0"
},
"autoload": {
"psr-0": {
"Codeliner\\ArrayReader\\": "src",
"psr-4": {
"Codeliner\\ArrayReader\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Codeliner\\ArrayReaderTest\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit -vvv"
}
}
4 changes: 2 additions & 2 deletions tests/phpunit.xml.dist → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="bootstrap.php">
<phpunit bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="ArrayReaderTest">
<directory>./Codeliner/ArrayReaderTest</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
54 changes: 11 additions & 43 deletions src/Codeliner/ArrayReader/ArrayReader.php → src/ArrayReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ArrayReader
/**
* @var array
*/
private $originalArray = array();
private $originalArray = [];

/**
* @param array $anArray
Expand All @@ -32,12 +32,7 @@ public function __construct(array $anArray)
$this->originalArray = $anArray;
}

/**
* @param string $aPath
* @param int $default
* @return int
*/
public function integerValue($aPath, $default = 0)
public function integerValue(string $aPath, int $default = 0): int
{
$value = $this->getValueFromPath($aPath);

Expand All @@ -48,12 +43,7 @@ public function integerValue($aPath, $default = 0)
return \intval($value);
}

/**
* @param string $aPath
* @param float $default
* @return float
*/
public function floatValue($aPath, $default = 0.0)
public function floatValue(string $aPath, float $default = 0.0): float
{
$value = $this->getValueFromPath($aPath);

Expand All @@ -64,12 +54,7 @@ public function floatValue($aPath, $default = 0.0)
return \floatval($value);
}

/**
* @param string $aPath
* @param bool $default
* @return bool
*/
public function booleanValue($aPath, $default = false)
public function booleanValue(string $aPath, bool $default = false): bool
{
$value = $this->getValueFromPath($aPath);

Expand All @@ -80,12 +65,7 @@ public function booleanValue($aPath, $default = false)
return (bool)$value;
}

/**
* @param string $aPath
* @param string $default
* @return string
*/
public function stringValue($aPath, $default = '')
public function stringValue(string $aPath, string $default = ''): string
{
$value = $this->getValueFromPath($aPath);

Expand All @@ -96,12 +76,7 @@ public function stringValue($aPath, $default = '')
return \strval($value);
}

/**
* @param string $aPath
* @param array $default
* @return array
*/
public function arrayValue($aPath, array $default = array())
public function arrayValue(string $aPath, array $default = []): array
{
$value = $this->getValueFromPath($aPath);

Expand All @@ -122,10 +97,10 @@ public function arrayValue($aPath, array $default = array())

/**
* @param string $aPath
* @param null $default
* @param mixed $default
* @return mixed
*/
public function mixedValue($aPath, $default = null)
public function mixedValue(string $aPath, $default = null)
{
$value = $this->getValueFromPath($aPath);

Expand All @@ -136,19 +111,12 @@ public function mixedValue($aPath, $default = null)
return $value;
}

/**
* @return array
*/
public function toArray()
public function toArray(): array
{
return $this->originalArray;
}

/**
* @param string $aPath
* @return array
*/
protected function toPathKeys($aPath)
protected function toPathKeys(string $aPath): array
{
$aPath = str_replace('\.', '___IamADot___', $aPath);
$parts = explode('.', $aPath);
Expand All @@ -160,7 +128,7 @@ protected function toPathKeys($aPath)
* @param string $aPath
* @return mixed
*/
protected function getValueFromPath($aPath)
protected function getValueFromPath(string $aPath)
{
$pathKeys = $this->toPathKeys($aPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
namespace Codeliner\ArrayReaderTest;

use Codeliner\ArrayReader\ArrayReader;
use PHPUnit\Framework\TestCase;

/**
* Class ArrayReaderTest
*
* @package Codeliner\ArrayReaderTest
* @author Alexander Miertsch <[email protected]>
*/
class ArrayReaderTest extends \PHPUnit_Framework_TestCase
class ArrayReaderTest extends TestCase
{
/**
* @test
Expand Down