Skip to content

Commit

Permalink
b3.0.0 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
s3b4stian committed Mar 23, 2021
1 parent 0d76185 commit 86b4751
Show file tree
Hide file tree
Showing 22 changed files with 1,877 additions and 34 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
clover.xml
infection-log.txt
vendor/
.phpunit.result.cache
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"issues": "https://github.com/linna/typed-array/issues"
},
"require": {
"php": "^7.1"
"php": ">=7.4"
},
"require-dev": {
"infection/infection": "^0.10",
"phpstan/phpstan": "^0.10",
"phpunit/phpunit": "^7.0"
"infection/infection": "^0.21",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Linna\\": "src/"
"Linna\\": "src/Linna"
}
},
"autoload-dev": {
Expand Down
29 changes: 15 additions & 14 deletions phpunit.xml
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>
87 changes: 87 additions & 0 deletions src/Linna/TypedArrayObject/ArrayArrayObject.php
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);
}
}
87 changes: 87 additions & 0 deletions src/Linna/TypedArrayObject/BoolArrayObject.php
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);
}
}
87 changes: 87 additions & 0 deletions src/Linna/TypedArrayObject/CallableArrayObject.php
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);
}
}
Loading

0 comments on commit 86b4751

Please sign in to comment.