Skip to content

Commit d8c16bf

Browse files
committed
fix CollectionFetch.php
1 parent 7bf0ee4 commit d8c16bf

File tree

15 files changed

+518
-49
lines changed

15 files changed

+518
-49
lines changed

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
"autoload-dev": {
1818
"psr-4": {
1919
"Test\\Eukles\\": "tests/",
20-
"Eukles\\": "tests/",
21-
"Util\\": "tests/util/",
22-
"Eukles\\Test\\Util\\": "tests/util/"
20+
"Eukles\\": "tests/"
2321
}
2422
},
2523
"require": {
2624
"php": ">=7.0",
2725
"ext-json": "*",
28-
"wollanup/php-api-rest-utils": "^1.1",
2926
"crell/api-problem": "^2.0",
3027
"akrabat/rka-content-type-renderer": "^0.7.3",
3128
"vlucas/phpdotenv": "^2.4",

src/Util/ClassName/ClassName.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: steve
5+
* Date: 01/02/17
6+
* Time: 13:53
7+
*/
8+
9+
namespace Eukles\Util\ClassName;
10+
11+
/**
12+
* Class ClassNameList
13+
*
14+
* @package Eukles\Util
15+
*/
16+
class ClassName
17+
{
18+
19+
/**
20+
* @param $file
21+
*
22+
* @return string
23+
* @throws FileNotFoundException
24+
* @throws InvalidClassException
25+
*/
26+
final public static function getFromFile($file)
27+
{
28+
if (!is_readable($file)) {
29+
throw new FileNotFoundException;
30+
}
31+
32+
$fp = fopen($file, 'r');
33+
$class = $namespace = $buffer = '';
34+
$i = 0;
35+
while (!$class) {
36+
if (feof($fp)) {
37+
break;
38+
}
39+
40+
$buffer .= fread($fp, 512);
41+
$tokens = @token_get_all($buffer);
42+
43+
if (strpos($buffer, '{') === false) {
44+
continue;
45+
}
46+
$total = count($tokens);
47+
for (; $i < $total; $i++) {
48+
if ($tokens[$i][0] === T_NAMESPACE) {
49+
for ($j = $i + 1; $j < count($tokens); $j++) {
50+
if ($tokens[$j][0] === T_STRING) {
51+
$namespace .= '\\' . $tokens[$j][1];
52+
} else {
53+
if ($tokens[$j] === '{' || $tokens[$j] === ';') {
54+
break;
55+
}
56+
}
57+
}
58+
} elseif ($tokens[$i][0] === T_CLASS) {
59+
for ($j = $i + 1; $j < count($tokens); $j++) {
60+
if ($tokens[$j] === '{') {
61+
$class = $tokens[$i + 2][1];
62+
break;
63+
}
64+
}
65+
break;
66+
}
67+
}
68+
}
69+
fclose($fp);
70+
if (!$class) {
71+
throw new InvalidClassException;
72+
}
73+
74+
return $namespace . '\\' . $class;
75+
}
76+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: steve
5+
* Date: 24/03/17
6+
* Time: 12:26
7+
*/
8+
9+
namespace Eukles\Util\ClassName;
10+
11+
use Exception;
12+
13+
class FileNotFoundException extends Exception
14+
{
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: steve
5+
* Date: 24/03/17
6+
* Time: 12:26
7+
*/
8+
9+
namespace Eukles\Util\ClassName;
10+
11+
use Exception;
12+
13+
class InvalidClassException extends Exception
14+
{
15+
16+
}

src/Util/DataIterator.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: steve
5+
* Date: 27/04/16
6+
* Time: 16:24
7+
*/
8+
9+
namespace Eukles\Util;
10+
11+
use ArrayAccess;
12+
use Iterator;
13+
14+
/**
15+
* Class DataIterator
16+
*
17+
* @package Eukles\Util
18+
*/
19+
class DataIterator implements Iterator, ArrayAccess
20+
{
21+
22+
protected $data = [];
23+
24+
/**
25+
* @return mixed
26+
*/
27+
final public function current()
28+
{
29+
return current($this->data);
30+
}
31+
32+
/**
33+
* @return mixed
34+
*/
35+
final public function key()
36+
{
37+
return key($this->data);
38+
}
39+
40+
/**
41+
*
42+
*/
43+
final public function next()
44+
{
45+
next($this->data);
46+
}
47+
48+
/**
49+
* @param mixed $offset
50+
*
51+
* @return bool
52+
*/
53+
final public function offsetExists($offset)
54+
{
55+
return array_key_exists($offset, $this->data);
56+
}
57+
58+
/**
59+
* @param mixed $offset
60+
*
61+
* @return mixed
62+
*/
63+
final public function offsetGet($offset)
64+
{
65+
return $this->data[$offset];
66+
}
67+
68+
/**
69+
* @param mixed $offset
70+
* @param mixed $value
71+
*/
72+
final public function offsetSet($offset, $value)
73+
{
74+
$this->data[$offset] = $value;
75+
}
76+
77+
/**
78+
* @param mixed $offset
79+
*/
80+
final public function offsetUnset($offset)
81+
{
82+
unset($this->data[$offset]);
83+
}
84+
85+
/**
86+
*
87+
*/
88+
final public function rewind()
89+
{
90+
reset($this->data);
91+
}
92+
93+
/**
94+
* @return bool
95+
*/
96+
final public function valid()
97+
{
98+
return (bool)!(key($this->data) === null);
99+
}
100+
}

src/Util/PksFinder.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: steve
5+
* Date: 21/04/17
6+
* Time: 09:54
7+
*/
8+
9+
namespace Eukles\Util;
10+
11+
class PksFinder
12+
{
13+
14+
/**
15+
* @var array
16+
*/
17+
protected $possiblePks = [];
18+
19+
/**
20+
* PksFinder constructor.
21+
*
22+
* @param array $possiblePkName
23+
*/
24+
public function __construct(array $possiblePkName = ['id'])
25+
{
26+
$this->possiblePks = $possiblePkName;
27+
}
28+
29+
/**
30+
* @param array|object $data
31+
*
32+
* @return array
33+
*/
34+
public function find(array $data)
35+
{
36+
if (empty($data)) {
37+
return [];
38+
}
39+
40+
foreach ($this->possiblePks as $possiblePk) {
41+
if (array_key_exists($possiblePk, $data)) {
42+
$foundPk = $data[$possiblePk];
43+
return is_array($foundPk) ? $foundPk : [$foundPk];
44+
}
45+
}
46+
47+
$pks = [];
48+
foreach ($data as $item) {
49+
if (is_scalar($item)) {
50+
$pks[] = $item;
51+
continue;
52+
}
53+
54+
if (is_object($item)) {
55+
$item = (array)$item;
56+
}
57+
if (is_array($item)) {
58+
foreach ($this->possiblePks as $possiblePk) {
59+
if (array_key_exists($possiblePk, $item)) {
60+
$pks[] = $item[$possiblePk];
61+
break;
62+
}
63+
}
64+
}
65+
}
66+
67+
return $pks;
68+
}
69+
}

tests/Service/Request/Pagination/RequestPaginationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
use Eukles\Service\Pagination\PaginationInterface;
1212
use Eukles\Service\Request\Pagination\RequestPagination;
13-
use Eukles\Test\Util\Request;
1413
use PHPUnit\Framework\TestCase;
14+
use Test\Eukles\Request;
1515

1616
class RequestPaginationTest extends TestCase
1717
{

tests/Service/Request/QueryModifier/Modifier/Base/ModifierBaseTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespace Eukles\Service\RequestQueryModifier\Base;
1313

1414
use Eukles\Service\Request\QueryModifier\Modifier\Base\ModifierBase;
15-
use Eukles\Test\Util\Request;
15+
use InvalidArgumentException;
1616
use PHPUnit\Framework\TestCase;
17+
use PHPUnit_Framework_MockObject_InvocationMocker;
18+
use Test\Eukles\Request;
1719

1820
/**
1921
* Class ModifierTestBase
@@ -24,13 +26,13 @@ class ModifierBaseTest extends TestCase
2426
{
2527

2628
/**
27-
* @var ModifierBase|\PHPUnit_Framework_MockObject_InvocationMocker $modifier
29+
* @var ModifierBase|PHPUnit_Framework_MockObject_InvocationMocker $modifier
2830
*/
2931
protected $modifier = null;
3032

3133
public function setUp()
3234
{
33-
/** @var ModifierBase|\PHPUnit_Framework_MockObject_InvocationMocker $modifier */
35+
/** @var ModifierBase|PHPUnit_Framework_MockObject_InvocationMocker $modifier */
3436
$this->modifier = $this->getMockForAbstractClass(ModifierBase::class, [new Request()]);
3537

3638
$this->modifier->expects($this->any())
@@ -57,7 +59,7 @@ public function testGetModifier()
5759
$r = new Request(["test" => json_encode(["property" => "name"])]);
5860
$this->modifier->setModifierFromRequest($r);
5961
$this->assertEquals(["property" => "name"], $this->modifier->getModifier('name'));
60-
$this->expectException(\InvalidArgumentException::class);
62+
$this->expectException(InvalidArgumentException::class);
6163
$this->modifier->getModifier('otherName');
6264
}
6365

0 commit comments

Comments
 (0)