Skip to content

Commit b46a663

Browse files
authored
Merge pull request #3 from minvws/chore/copy-original-source
chore: copy original source
2 parents 89f1ec6 + 9f5543c commit b46a663

File tree

15 files changed

+875
-1
lines changed

15 files changed

+875
-1
lines changed

.github/actions/setup/action.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Setup
2+
description: "Setup PHP and composer and install dependencies"
3+
4+
inputs:
5+
php-version:
6+
default: "8.3"
7+
coverage:
8+
default: xdebug
9+
composer-flags:
10+
default: ""
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Install PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: ${{ inputs.php-version }}
19+
coverage: ${{ inputs.coverage }}
20+
21+
- name: Get composer cache directory
22+
id: composer-cache
23+
shell: bash
24+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
25+
26+
- name: Cache dependencies
27+
uses: actions/cache@v4
28+
with:
29+
path: ${{ steps.composer-cache.outputs.dir }}
30+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
31+
restore-keys: ${{ runner.os }}-composer-
32+
33+
- name: Install dependencies
34+
shell: bash
35+
run: composer update --prefer-dist --no-interaction ${{ inputs.composer-flags }}

.github/workflows/ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
phpcs:
11+
runs-on: ubuntu-24.04
12+
name: PHPCS
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Setup
18+
uses: ./.github/actions/setup
19+
with:
20+
coverage: none
21+
22+
- name: Run PHPCS
23+
run: vendor/bin/phpcs
24+
25+
phpstan:
26+
runs-on: ubuntu-24.04
27+
name: PHPStan
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v2
31+
32+
- name: Setup
33+
uses: ./.github/actions/setup
34+
with:
35+
coverage: none
36+
37+
- name: Install optional dependency doctrine/dbal
38+
run: composer require doctrine/dbal
39+
40+
- name: Run PHPStan
41+
run: vendor/bin/phpstan analyse
42+
43+
test:
44+
runs-on: ubuntu-24.04
45+
strategy:
46+
max-parallel: 3
47+
matrix:
48+
php-version: [ 8.2, 8.3 ]
49+
composer-flags: [ "", "--prefer-lowest" ]
50+
name: Test on PHP ${{ matrix.php-version }} ${{ matrix.composer-flags }}
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v2
54+
55+
- name: Setup
56+
uses: ./.github/actions/setup
57+
with:
58+
php-version: ${{ matrix.php-version }}
59+
composer-flags: ${{ matrix.composer-flags }}
60+
61+
- name: Run tests (Unit and Feature)
62+
run: vendor/bin/phpunit --coverage-text

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
clover.xml
2+
html/
3+
vendor/*
4+
composer.lock
5+
.phpunit.result.cache

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2022, Joshua Thijssen
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
Auto-generated README for icore-php-typearray
1+
# Typed Array
2+
3+
Simple wrapper around property-accessor to fetch elements in a typed way. This package is created because I was fiddling around with a lot of json-arrays
4+
that were not typed and phpstan had a big issue with that.
5+
6+
So, instead of having `mixed[] $myarray`, we can use `TypeArray`, and fetch elements with:
7+
8+
```
9+
$arr = new TypeArray(['foo' => 'string', 'bar' => 4 ]);
10+
11+
$arr->getString('[foo]'); // always returns a string
12+
$arr->getString('[notexists]', 'defaultval'); // Returns default val when not found
13+
14+
$arr->getInt('[bar]'); // returns int(4)
15+
$arr->getInt('[foo]'); // Returns InvalidTypeException as this element is a string, not an int
16+
17+
```
18+
19+
See symfony propertyaccess component for the path syntax used.

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "minvws/icore-php-typearray",
3+
"description": "Typed Array",
4+
"type": "library",
5+
"require": {
6+
"php": ">=8.0.2",
7+
"symfony/property-access": "^6.0"
8+
},
9+
"require-dev": {
10+
"phpunit/phpunit": "^9.5",
11+
"squizlabs/php_codesniffer": "^3.6",
12+
"phpstan/phpstan": "^1.0"
13+
},
14+
"suggest": {
15+
"doctrine/dbal": "For using type_array directly with Doctrine"
16+
},
17+
"license": "BSD-3-Clause",
18+
"autoload": {
19+
"psr-4": {
20+
"MinVWS\\TypeArray\\": "src/"
21+
}
22+
},
23+
"authors": [
24+
{
25+
"name": "Joshua Thijssen",
26+
"email": "jthijssen@noxlogic.nl"
27+
}
28+
],
29+
"scripts": {
30+
"test": [
31+
"vendor/bin/phpcs",
32+
"vendor/bin/phpstan",
33+
"vendor/bin/phpunit"
34+
]
35+
}
36+
}

phpcs.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="."/>
4+
5+
<file>./src</file>
6+
<file>./tests</file>
7+
8+
<rule ref="PSR12" />
9+
</ruleset>

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
paths:
3+
- src
4+
level: 8
5+
inferPrivatePropertyTypeFromConstructor: true
6+
reportUnmatchedIgnoredErrors: false

phpunit.xml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory>./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="TypeArray Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
</phpunit>

phpunit.xml.dist.bak

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
backupGlobals = "false"
4+
backupStaticAttributes = "false"
5+
colors = "true"
6+
convertErrorsToExceptions = "true"
7+
convertNoticesToExceptions = "true"
8+
convertWarningsToExceptions = "true"
9+
processIsolation = "false"
10+
stopOnFailure = "false">
11+
12+
<testsuites>
13+
<testsuite name="TypeArray Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
18+
<filter>
19+
<whitelist>
20+
<directory>./src</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>

0 commit comments

Comments
 (0)