Skip to content

Commit 86b4751

Browse files
committed
b3.0.0 initial commit
1 parent 0d76185 commit 86b4751

22 files changed

+1877
-34
lines changed

.github/workflows/tests.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
php: [7.4, 8.0]
17+
18+
name: PHP ${{ matrix.php }}
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Install PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
tools: composer:v2
29+
coverage: xdebug
30+
31+
- name: Install dependencies
32+
run: composer install
33+
34+
- name: Execute tests
35+
run: vendor/bin/phpunit --verbose

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ composer.lock
33
clover.xml
44
infection-log.txt
55
vendor/
6+
.phpunit.result.cache

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
"issues": "https://github.com/linna/typed-array/issues"
1616
},
1717
"require": {
18-
"php": "^7.1"
18+
"php": ">=7.4"
1919
},
2020
"require-dev": {
21-
"infection/infection": "^0.10",
22-
"phpstan/phpstan": "^0.10",
23-
"phpunit/phpunit": "^7.0"
21+
"infection/infection": "^0.21",
22+
"phpstan/phpstan": "^0.12",
23+
"phpunit/phpunit": "^9.0"
2424
},
2525
"autoload": {
2626
"psr-4": {
27-
"Linna\\": "src/"
27+
"Linna\\": "src/Linna"
2828
}
2929
},
3030
"autoload-dev": {

phpunit.xml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" bootstrap="vendor/autoload.php" verbose="true">
3-
<testsuites>
4-
<testsuite name="Linna Array Test Suite">
5-
<directory suffix="Test.php">tests</directory>
6-
</testsuite>
7-
</testsuites>
8-
<filter>
9-
<whitelist>
10-
<directory suffix=".php">src</directory>
11-
</whitelist>
12-
</filter>
13-
<logging>
14-
<log type="coverage-clover" target="clover.xml"/>
15-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
<report>
8+
<clover outputFile="clover.xml"/>
9+
</report>
10+
</coverage>
11+
<testsuites>
12+
<testsuite name="Linna Array Test Suite">
13+
<directory suffix="Test.php">tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<logging/>
1617
</phpunit>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/**
4+
* Linna Array.
5+
*
6+
* @author Sebastian Rapetti <sebastian.rapetti@alice.it>
7+
* @copyright (c) 2018, Sebastian Rapetti
8+
* @license http://opensource.org/licenses/MIT MIT License
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Linna\TypedArrayObject;
13+
14+
use ArrayObject;
15+
use InvalidArgumentException;
16+
17+
/**
18+
* Provide a way to create an array of array typed elements with php.
19+
*/
20+
class ArrayArrayObject extends ArrayObject
21+
{
22+
public const EXC_MESSAGE = 'Elements passed must be of the type <array>.';
23+
24+
/**
25+
* Class Contructor.
26+
*
27+
* @param array $input
28+
* @param int $flags
29+
* @param string $iterator_class
30+
*
31+
* @throws InvalidArgumentException If elements in the optional array parameter
32+
* aren't of the configured type.
33+
*/
34+
public function __construct(array $input = [], int $flags = 0, string $iterator_class = "ArrayIterator")
35+
{
36+
//to avoid foreach, compare sizes of array
37+
//before and after apply a filter :)
38+
if (\count($input) > \count(\array_filter($input, 'is_array'))) {
39+
throw new InvalidArgumentException(self::EXC_MESSAGE);
40+
}
41+
42+
//call parent constructor
43+
parent::__construct($input, $flags, $iterator_class);
44+
}
45+
46+
/**
47+
* Array style value assignment.
48+
*
49+
* @ignore
50+
*
51+
* @param mixed $index
52+
* @param array $newval
53+
*
54+
* @throws InvalidArgumentException If value passed with $newval are not of the array type
55+
*
56+
* @return void
57+
*/
58+
public function offsetSet($index, $newval): void
59+
{
60+
if (\is_array($newval)) {
61+
parent::offsetSet($index, $newval);
62+
63+
return;
64+
}
65+
66+
throw new InvalidArgumentException(self::EXC_MESSAGE);
67+
}
68+
69+
/**
70+
* Append a value at the end of the array.
71+
*
72+
* @param array $value
73+
* @return void
74+
*
75+
* @throws InvalidArgumentException If value passed with $value are not of the array type
76+
*/
77+
public function append($value): void
78+
{
79+
if (\is_array($value)) {
80+
parent::append($value);
81+
82+
return;
83+
}
84+
85+
throw new InvalidArgumentException(self::EXC_MESSAGE);
86+
}
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/**
4+
* Linna Array.
5+
*
6+
* @author Sebastian Rapetti <sebastian.rapetti@alice.it>
7+
* @copyright (c) 2018, Sebastian Rapetti
8+
* @license http://opensource.org/licenses/MIT MIT License
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Linna\TypedArrayObject;
13+
14+
use ArrayObject;
15+
use InvalidArgumentException;
16+
17+
/**
18+
* Provide a way to create an array of boolean typed elements with php.
19+
*/
20+
class BoolArrayObject extends ArrayObject
21+
{
22+
public const EXC_MESSAGE = 'Elements passed must be of the type <bool>.';
23+
24+
/**
25+
* Class Contructor.
26+
*
27+
* @param array $input
28+
* @param int $flags
29+
* @param string $iterator_class
30+
*
31+
* @throws InvalidArgumentException If elements in the optional array parameter
32+
* aren't of the configured type.
33+
*/
34+
public function __construct(array $input = [], int $flags = 0, string $iterator_class = "ArrayIterator")
35+
{
36+
//to avoid foreach, compare sizes of array
37+
//before and after apply a filter :)
38+
if (\count($input) > \count(\array_filter($input, 'is_bool'))) {
39+
throw new InvalidArgumentException(self::EXC_MESSAGE);
40+
}
41+
42+
//call parent constructor
43+
parent::__construct($input, $flags, $iterator_class);
44+
}
45+
46+
/**
47+
* Array style value assignment.
48+
*
49+
* @ignore
50+
*
51+
* @param mixed $index
52+
* @param bool $newval
53+
*
54+
* @throws InvalidArgumentException If value passed with $newval are not of the boolean type
55+
*
56+
* @return void
57+
*/
58+
public function offsetSet($index, $newval): void
59+
{
60+
if (\is_bool($newval)) {
61+
parent::offsetSet($index, $newval);
62+
63+
return;
64+
}
65+
66+
throw new InvalidArgumentException(self::EXC_MESSAGE);
67+
}
68+
69+
/**
70+
* Append a value at the end of the array.
71+
*
72+
* @param bool $value
73+
* @return void
74+
*
75+
* @throws InvalidArgumentException If value passed with $value are not of the boolean type
76+
*/
77+
public function append($value): void
78+
{
79+
if (\is_bool($value)) {
80+
parent::append($value);
81+
82+
return;
83+
}
84+
85+
throw new InvalidArgumentException(self::EXC_MESSAGE);
86+
}
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/**
4+
* Linna Array.
5+
*
6+
* @author Sebastian Rapetti <sebastian.rapetti@alice.it>
7+
* @copyright (c) 2018, Sebastian Rapetti
8+
* @license http://opensource.org/licenses/MIT MIT License
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Linna\TypedArrayObject;
13+
14+
use ArrayObject;
15+
use InvalidArgumentException;
16+
17+
/**
18+
* Provide a way to create an array of callable typed elements with php.
19+
*/
20+
class CallableArrayObject extends ArrayObject
21+
{
22+
public const EXC_MESSAGE = 'Elements passed must be of the type <callable>.';
23+
24+
/**
25+
* Class Contructor.
26+
*
27+
* @param array $input
28+
* @param int $flags
29+
* @param string $iterator_class
30+
*
31+
* @throws InvalidArgumentException If elements in the optional array parameter
32+
* aren't of the configured type.
33+
*/
34+
public function __construct(array $input = [], int $flags = 0, string $iterator_class = "ArrayIterator")
35+
{
36+
//to avoid foreach, compare sizes of array
37+
//before and after apply a filter :)
38+
if (\count($input) > \count(\array_filter($input, 'is_callable'))) {
39+
throw new InvalidArgumentException(self::EXC_MESSAGE);
40+
}
41+
42+
//call parent constructor
43+
parent::__construct($input, $flags, $iterator_class);
44+
}
45+
46+
/**
47+
* Array style value assignment.
48+
*
49+
* @ignore
50+
*
51+
* @param mixed $index
52+
* @param int $newval
53+
*
54+
* @throws InvalidArgumentException If value passed with $newval are not of the integer type
55+
*
56+
* @return void
57+
*/
58+
public function offsetSet($index, $newval): void
59+
{
60+
if (\is_callable($newval)) {
61+
parent::offsetSet($index, $newval);
62+
63+
return;
64+
}
65+
66+
throw new InvalidArgumentException(self::EXC_MESSAGE);
67+
}
68+
69+
/**
70+
* Append a value at the end of the array.
71+
*
72+
* @param int $value
73+
* @return void
74+
*
75+
* @throws InvalidArgumentException If value passed with $value are not of the integer type
76+
*/
77+
public function append($value): void
78+
{
79+
if (\is_callable($value)) {
80+
parent::append($value);
81+
82+
return;
83+
}
84+
85+
throw new InvalidArgumentException(self::EXC_MESSAGE);
86+
}
87+
}

0 commit comments

Comments
 (0)