-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,877 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: [7.4, 8.0] | ||
|
||
name: PHP ${{ matrix.php }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
tools: composer:v2 | ||
coverage: xdebug | ||
|
||
- name: Install dependencies | ||
run: composer install | ||
|
||
- name: Execute tests | ||
run: vendor/bin/phpunit --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ composer.lock | |
clover.xml | ||
infection-log.txt | ||
vendor/ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit colors="true" bootstrap="vendor/autoload.php" verbose="true"> | ||
<testsuites> | ||
<testsuite name="Linna Array Test Suite"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-clover" target="clover.xml"/> | ||
</logging> | ||
<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"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="clover.xml"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Linna Array Test Suite"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging/> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* Linna Array. | ||
* | ||
* @author Sebastian Rapetti <[email protected]> | ||
* @copyright (c) 2018, Sebastian Rapetti | ||
* @license http://opensource.org/licenses/MIT MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Linna\TypedArrayObject; | ||
|
||
use ArrayObject; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* Provide a way to create an array of array typed elements with php. | ||
*/ | ||
class ArrayArrayObject extends ArrayObject | ||
{ | ||
public const EXC_MESSAGE = 'Elements passed must be of the type <array>.'; | ||
|
||
/** | ||
* Class Contructor. | ||
* | ||
* @param array $input | ||
* @param int $flags | ||
* @param string $iterator_class | ||
* | ||
* @throws InvalidArgumentException If elements in the optional array parameter | ||
* aren't of the configured type. | ||
*/ | ||
public function __construct(array $input = [], int $flags = 0, string $iterator_class = "ArrayIterator") | ||
{ | ||
//to avoid foreach, compare sizes of array | ||
//before and after apply a filter :) | ||
if (\count($input) > \count(\array_filter($input, 'is_array'))) { | ||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
|
||
//call parent constructor | ||
parent::__construct($input, $flags, $iterator_class); | ||
} | ||
|
||
/** | ||
* Array style value assignment. | ||
* | ||
* @ignore | ||
* | ||
* @param mixed $index | ||
* @param array $newval | ||
* | ||
* @throws InvalidArgumentException If value passed with $newval are not of the array type | ||
* | ||
* @return void | ||
*/ | ||
public function offsetSet($index, $newval): void | ||
{ | ||
if (\is_array($newval)) { | ||
parent::offsetSet($index, $newval); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
|
||
/** | ||
* Append a value at the end of the array. | ||
* | ||
* @param array $value | ||
* @return void | ||
* | ||
* @throws InvalidArgumentException If value passed with $value are not of the array type | ||
*/ | ||
public function append($value): void | ||
{ | ||
if (\is_array($value)) { | ||
parent::append($value); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* Linna Array. | ||
* | ||
* @author Sebastian Rapetti <[email protected]> | ||
* @copyright (c) 2018, Sebastian Rapetti | ||
* @license http://opensource.org/licenses/MIT MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Linna\TypedArrayObject; | ||
|
||
use ArrayObject; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* Provide a way to create an array of boolean typed elements with php. | ||
*/ | ||
class BoolArrayObject extends ArrayObject | ||
{ | ||
public const EXC_MESSAGE = 'Elements passed must be of the type <bool>.'; | ||
|
||
/** | ||
* Class Contructor. | ||
* | ||
* @param array $input | ||
* @param int $flags | ||
* @param string $iterator_class | ||
* | ||
* @throws InvalidArgumentException If elements in the optional array parameter | ||
* aren't of the configured type. | ||
*/ | ||
public function __construct(array $input = [], int $flags = 0, string $iterator_class = "ArrayIterator") | ||
{ | ||
//to avoid foreach, compare sizes of array | ||
//before and after apply a filter :) | ||
if (\count($input) > \count(\array_filter($input, 'is_bool'))) { | ||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
|
||
//call parent constructor | ||
parent::__construct($input, $flags, $iterator_class); | ||
} | ||
|
||
/** | ||
* Array style value assignment. | ||
* | ||
* @ignore | ||
* | ||
* @param mixed $index | ||
* @param bool $newval | ||
* | ||
* @throws InvalidArgumentException If value passed with $newval are not of the boolean type | ||
* | ||
* @return void | ||
*/ | ||
public function offsetSet($index, $newval): void | ||
{ | ||
if (\is_bool($newval)) { | ||
parent::offsetSet($index, $newval); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
|
||
/** | ||
* Append a value at the end of the array. | ||
* | ||
* @param bool $value | ||
* @return void | ||
* | ||
* @throws InvalidArgumentException If value passed with $value are not of the boolean type | ||
*/ | ||
public function append($value): void | ||
{ | ||
if (\is_bool($value)) { | ||
parent::append($value); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* Linna Array. | ||
* | ||
* @author Sebastian Rapetti <[email protected]> | ||
* @copyright (c) 2018, Sebastian Rapetti | ||
* @license http://opensource.org/licenses/MIT MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Linna\TypedArrayObject; | ||
|
||
use ArrayObject; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* Provide a way to create an array of callable typed elements with php. | ||
*/ | ||
class CallableArrayObject extends ArrayObject | ||
{ | ||
public const EXC_MESSAGE = 'Elements passed must be of the type <callable>.'; | ||
|
||
/** | ||
* Class Contructor. | ||
* | ||
* @param array $input | ||
* @param int $flags | ||
* @param string $iterator_class | ||
* | ||
* @throws InvalidArgumentException If elements in the optional array parameter | ||
* aren't of the configured type. | ||
*/ | ||
public function __construct(array $input = [], int $flags = 0, string $iterator_class = "ArrayIterator") | ||
{ | ||
//to avoid foreach, compare sizes of array | ||
//before and after apply a filter :) | ||
if (\count($input) > \count(\array_filter($input, 'is_callable'))) { | ||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
|
||
//call parent constructor | ||
parent::__construct($input, $flags, $iterator_class); | ||
} | ||
|
||
/** | ||
* Array style value assignment. | ||
* | ||
* @ignore | ||
* | ||
* @param mixed $index | ||
* @param int $newval | ||
* | ||
* @throws InvalidArgumentException If value passed with $newval are not of the integer type | ||
* | ||
* @return void | ||
*/ | ||
public function offsetSet($index, $newval): void | ||
{ | ||
if (\is_callable($newval)) { | ||
parent::offsetSet($index, $newval); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
|
||
/** | ||
* Append a value at the end of the array. | ||
* | ||
* @param int $value | ||
* @return void | ||
* | ||
* @throws InvalidArgumentException If value passed with $value are not of the integer type | ||
*/ | ||
public function append($value): void | ||
{ | ||
if (\is_callable($value)) { | ||
parent::append($value); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(self::EXC_MESSAGE); | ||
} | ||
} |
Oops, something went wrong.