Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Mar 10, 2024
0 parents commit 1d2d85d
Show file tree
Hide file tree
Showing 31 changed files with 1,236 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/test_master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: PHP Version Check
run: php -v

- name: Validate Composer JSON
run: composer validate

- name: Run Composer
run: composer install --no-interaction

- name: Unit tests
run: |
composer test-init
composer test
- name: PHP Code Sniffer
run: composer codesniffer

- name: PHPStan analysis
run: composer stan

code-coverage:
name: Code coverage
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.4']

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run Composer
run: composer install --no-interaction

- name: Unit tests
run: |
composer test-init
composer test-coverage-xml
mkdir -p ./build/logs
cp ./tests/_output/coverage.xml ./build/logs/clover.xml
- name: Code Coverage (Coveralls)
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: php vendor/bin/php-coveralls -v
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vendor
.idea
tests/_output
tests/_support/_generated
composer.lock
composer.phar
build
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Required to run your project under the correct environment
language: php

# Versions of PHP you want your project run with
php:
- 7.4
- 8.0
- 8.1

# fast_finish: If your build fails do not continue trying to build, just stop.
matrix:
fast_finish: true
include:
- php: 7.4
- php: 8.0
- php: 8.1

# Update composer
before-install:
- composer self-update

# Install composer dependencies, init codeception
install:
- composer install --no-interaction --dev
- composer test-init

# Run script
script:
- composer test
- composer codesniffer
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Smoren

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Schematic data mapper
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/smoren/array-view)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Smoren/array-view-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Smoren/array-view-php/?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/Smoren/array-view-php/badge.svg?branch=master)](https://coveralls.io/github/Smoren/array-view-php?branch=master)
![Build and test](https://github.com/Smoren/array-view-php/actions/workflows/test_master.yml/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

TODO

## How to install to your project
```
composer require smoren/array-view
```

## Usage
TODO

## Unit testing
```
composer install
composer test-init
composer test
```

## Standards
ArrayView conforms to the following standards:

* PSR-1 — [Basic coding standard](https://www.php-fig.org/psr/psr-1/)
* PSR-4 — [Autoloader](https://www.php-fig.org/psr/psr-4/)
* PSR-12 — [Extended coding style guide](https://www.php-fig.org/psr/psr-12/)

## License
ArrayView is licensed under the MIT License.
20 changes: 20 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
actor: Tester
bootstrap: _bootstrap.php
paths:
tests: tests
log: tests/_output
output: tests/_output
data: tests/_data
helpers: tests/_support
settings:
memory_limit: 1024M
colors: true
coverage:
#c3_url: http://localhost:8080/index-test.php/
enabled: true
show_uncovered: false
include:
- src/*
exclude:
- vendor/*
- tests/*
49 changes: 49 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "smoren/array-view",
"description": "Schematic data converter",
"keywords": ["converter", "schema"],
"license": "MIT",
"authors": [
{
"name": "Smoren",
"email": "ofigate@gmail.com"
}
],
"require": {
"php": ">=7.4"
},
"require-dev": {
"codeception/codeception": "^4.2.1",
"codeception/module-asserts": "^2.0",
"php-coveralls/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "3.*",
"phpstan/phpstan": "^1.8"
},
"autoload": {
"psr-4": {
"Smoren\\ArrayView\\": "src",
"Smoren\\ArrayView\\Tests\\Unit\\": "tests/unit"
}
},
"config": {
"fxp-asset": {
"enabled": false
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"scripts": {
"test-init": ["./vendor/bin/codecept build"],
"test-all": ["composer test-coverage", "composer codesniffer", "composer stan"],
"test": ["./vendor/bin/codecept run unit tests/unit"],
"test-coverage": ["./vendor/bin/codecept run unit tests/unit --coverage"],
"test-coverage-html": ["./vendor/bin/codecept run unit tests/unit --coverage-html"],
"test-coverage-xml": ["./vendor/bin/codecept run unit tests/unit --coverage-xml"],
"codesniffer": ["./vendor/bin/phpcs --ignore=vendor,tests --standard=tests/coding_standard.xml -s ."],
"stan": ["./vendor/bin/phpstan analyse -l 9 src"]
}
}
Binary file added docs/images/schemator-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/Exceptions/IndexError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Smoren\ArrayView\Exceptions;

class IndexError extends \RuntimeException
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/KeyError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Smoren\ArrayView\Exceptions;

class KeyError extends \RuntimeException
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/LengthError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Smoren\ArrayView\Exceptions;

class LengthError extends \RuntimeException
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/NotSupportedError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Smoren\ArrayView\Exceptions;

class NotSupportedError extends \Exception
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/ReadonlyError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Smoren\ArrayView\Exceptions;

class ReadonlyError extends \RuntimeException
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/ValueError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Smoren\ArrayView\Exceptions;

class ValueError extends \RuntimeException
{
}
16 changes: 16 additions & 0 deletions src/Interfaces/ArraySelectorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Smoren\ArrayView\Interfaces;

interface ArraySelectorInterface
{
/**
* @template T
* @param ArrayViewInterface<T> $source
* @param bool|null $readonly
* @return ArrayViewInterface<T>
*/
public function select(ArrayViewInterface $source, ?bool $readonly = null): ArrayViewInterface;
}
70 changes: 70 additions & 0 deletions src/Interfaces/ArrayViewInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Smoren\ArrayView\Interfaces;

use Smoren\ArrayView\Views\ArrayView;

/**
* @template T
* @extends \ArrayAccess<int, T>
*/
interface ArrayViewInterface extends \ArrayAccess, \Countable, \IteratorAggregate

Check failure on line 13 in src/Interfaces/ArrayViewInterface.php

View workflow job for this annotation

GitHub Actions / Test (8.1)

Interface Smoren\ArrayView\Interfaces\ArrayViewInterface extends generic interface IteratorAggregate but does not specify its types: TKey, TValue

Check failure on line 13 in src/Interfaces/ArrayViewInterface.php

View workflow job for this annotation

GitHub Actions / Test (8.2)

Interface Smoren\ArrayView\Interfaces\ArrayViewInterface extends generic interface IteratorAggregate but does not specify its types: TKey, TValue
{
/**
* @param array<T>|ArrayView<T> $source
* @param bool|null $readonly
* @return ArrayView<T>
*/
public static function toView(&$source, ?bool $readonly = null): ArrayView;

/**
* @return array<T>
*/
public function toArray(): array;

/**
* @param callable(T): bool $predicate
* @return ArrayViewInterface
*/
public function filter(callable $predicate): ArrayViewInterface;

Check failure on line 31 in src/Interfaces/ArrayViewInterface.php

View workflow job for this annotation

GitHub Actions / Test (8.1)

Method Smoren\ArrayView\Interfaces\ArrayViewInterface::filter() return type with generic interface Smoren\ArrayView\Interfaces\ArrayViewInterface does not specify its types: T

Check failure on line 31 in src/Interfaces/ArrayViewInterface.php

View workflow job for this annotation

GitHub Actions / Test (8.2)

Method Smoren\ArrayView\Interfaces\ArrayViewInterface::filter() return type with generic interface Smoren\ArrayView\Interfaces\ArrayViewInterface does not specify its types: T

/**
* @param callable(T): bool $predicate
* @return ArraySelectorInterface
*/
public function is(callable $predicate): ArraySelectorInterface;

/**
* @param ArraySelectorInterface|string $selector
* @param bool|null $readonly
* @return ArrayViewInterface<T>
*/
public function subview($selector, bool $readonly = null): ArrayViewInterface;

/**
* @param callable(T, int): T $mapper
* @return ArrayViewInterface<T>
*/
public function apply(callable $mapper): self;

/**
* @template U
* @param array<U>|ArrayViewInterface<U> $data
* @param callable(T, U, int): T $mapper
* @return ArrayViewInterface<T>
*/
public function applyWith($data, callable $mapper): self;

/**
* @param array<T>|ArrayView<T> $newValues
* @return ArrayViewInterface<T>
*/
public function set($newValues): self;

/**
* @return bool
*/
public function isReadonly(): bool;
}
Loading

0 comments on commit 1d2d85d

Please sign in to comment.