-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
0 parents
commit a314851
Showing
19 changed files
with
456 additions
and
0 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,18 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.yml] | ||
indent_size = 2 |
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,16 @@ | ||
/art export-ignore | ||
/docs export-ignore | ||
/tests export-ignore | ||
/types | ||
/scripts export-ignore | ||
/.github export-ignore | ||
/.php_cs export-ignore | ||
.editorconfig export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
phpstan.neon.dist export-ignore | ||
phpunit.xml.dist export-ignore | ||
rector.php export-ignore | ||
CHANGELOG.md export-ignore | ||
CONTRIBUTING.md export-ignore | ||
README.md export-ignore |
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,5 @@ | ||
# These are supported funding model platforms | ||
|
||
github: nunomaduro | ||
patreon: nunomaduro | ||
custom: https://www.paypal.com/paypalme/enunomaduro |
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,49 @@ | ||
name: Formats | ||
|
||
on: ['push', 'pull_request'] | ||
|
||
jobs: | ||
ci: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ubuntu-latest] | ||
php: [8.2] | ||
dependency-version: [prefer-lowest, prefer-stable] | ||
|
||
name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} | ||
|
||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, mbstring, zip | ||
coverage: pcov | ||
|
||
- name: Get Composer cache directory | ||
id: composer-cache | ||
shell: bash | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }} | ||
restore-keys: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer- | ||
|
||
- name: Install Composer dependencies | ||
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist | ||
|
||
- name: Coding Style Checks | ||
run: composer test:lint | ||
|
||
- name: Type Checks | ||
run: composer test:types |
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,45 @@ | ||
name: Tests | ||
|
||
on: ['push', 'pull_request'] | ||
|
||
jobs: | ||
ci: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
php: ['8.2', '8.3'] | ||
dependency-version: [prefer-lowest, prefer-stable] | ||
|
||
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} | ||
|
||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, mbstring, zip | ||
coverage: none | ||
|
||
- name: Get Composer cache directory | ||
id: composer-cache | ||
shell: bash | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }} | ||
restore-keys: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer- | ||
|
||
- name: Install Composer dependencies | ||
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist | ||
|
||
- name: Integration Tests | ||
run: php ./vendor/bin/pest |
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,9 @@ | ||
/.phpunit.result.cache | ||
/.phpunit.cache | ||
/.php-cs-fixer.cache | ||
/.php-cs-fixer.php | ||
/composer.lock | ||
/phpunit.xml | ||
/vendor/ | ||
*.swp | ||
*.swo |
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,8 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## [Unreleased] | ||
- Adds first version |
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,47 @@ | ||
# CONTRIBUTING | ||
|
||
Contributions are welcome, and are accepted via pull requests. | ||
Please review these guidelines before submitting any pull requests. | ||
|
||
## Process | ||
|
||
1. Fork the project | ||
1. Create a new branch | ||
1. Code, test, commit and push | ||
1. Open a pull request detailing your changes. Make sure to follow the [template](.github/PULL_REQUEST_TEMPLATE.md) | ||
|
||
## Guidelines | ||
|
||
* Please ensure the coding style running `composer lint`. | ||
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful. | ||
* You may need to [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) to avoid merge conflicts. | ||
* Please remember that we follow [SemVer](http://semver.org/). | ||
|
||
## Setup | ||
|
||
Clone your fork, then install the dev dependencies: | ||
```bash | ||
composer install | ||
``` | ||
## Lint | ||
|
||
Lint your code: | ||
```bash | ||
composer lint | ||
``` | ||
## Tests | ||
|
||
Run all tests: | ||
```bash | ||
composer test | ||
``` | ||
|
||
Check types: | ||
```bash | ||
composer test:types | ||
``` | ||
|
||
Unit tests: | ||
```bash | ||
composer test:unit | ||
``` |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Nuno Maduro <[email protected]> | ||
|
||
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. |
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,45 @@ | ||
<p align="center"> | ||
<img src="https://raw.githubusercontent.com/nunomaduro/skeleton-php/master/docs/example.jpg" height="300" alt="Skeleton Php"> | ||
<p align="center"> | ||
<a href="https://github.com/nunomaduro/skeleton-php/actions"><img alt="GitHub Workflow Status (master)" src="https://github.com/nunomaduro/skeleton-php/actions/workflows/tests.yml/badge.svg"></a> | ||
<a href="https://packagist.org/packages/nunomaduro/skeleton-php"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/nunomaduro/skeleton-php"></a> | ||
<a href="https://packagist.org/packages/nunomaduro/skeleton-php"><img alt="Latest Version" src="https://img.shields.io/packagist/v/nunomaduro/skeleton-php"></a> | ||
<a href="https://packagist.org/packages/nunomaduro/skeleton-php"><img alt="License" src="https://img.shields.io/packagist/l/nunomaduro/skeleton-php"></a> | ||
</p> | ||
</p> | ||
|
||
------ | ||
|
||
Type Guard is a lightweight PHP library that allows you to narrow down the type of an variable to a more specific type. It provides a `type` function to assert and tell the compiler, [PHPStan](https://phpstan.org/), and [Psalm](https://psalm.dev/) the type of a variable. Here is an example: | ||
|
||
```php | ||
function config(): mixed; | ||
|
||
$apiKey = config('api_key'); // $apiKey is mixed | ||
|
||
type($apiKey)->isString(); // PHPStan and Psalm will know that $apiKey is a string | ||
``` | ||
|
||
## Installation | ||
|
||
> **Requires [PHP 8.2+](https://php.net/releases/)** | ||
You may use [Composer](https://getcomposer.org) to install Type Guard into your PHP project: | ||
|
||
```bash | ||
composer require std-library/type-guard | ||
``` | ||
|
||
## Usage | ||
|
||
### `isString() | ||
|
||
Asserts that the given variable is a string. | ||
|
||
```php | ||
type($variable)->isString(); | ||
``` | ||
|
||
--- | ||
|
||
**Type Guard** was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[MIT license](https://opensource.org/licenses/MIT)**. |
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,63 @@ | ||
{ | ||
"name": "std-library/type-guard", | ||
"description": "Type Guard is a lightweight PHP library that allows you to narrow down the type of an variable to a more specific type.", | ||
"keywords": ["std-library", "type-guard", "assert", "narrow", "type", "php"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nuno Maduro", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.2.0" | ||
}, | ||
"require-dev": { | ||
"laravel/pint": "^1.15.0", | ||
"pestphp/pest": "^3.0.0", | ||
"pestphp/pest-plugin-type-coverage": "3.x-dev", | ||
"phpstan/phpstan": "^1.10.66", | ||
"rector/rector": "^1.0.3", | ||
"symfony/var-dumper": "^6.4.0|^7.0.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"StdLibrary\\TypeGuard\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\": "tests/" | ||
}, | ||
"files": [ | ||
"src/Functions.php" | ||
] | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"config": { | ||
"sort-packages": true, | ||
"preferred-install": "dist", | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true | ||
} | ||
}, | ||
"scripts": { | ||
"refacto": "rector", | ||
"lint": "pint", | ||
"refactor": "rector", | ||
"test:lint": "pint --test", | ||
"test:refactor": "rector --dry-run", | ||
"test:types": "phpstan analyse", | ||
"test:type-coverage": "pest --type-coverage --min=100", | ||
"test:unit": "pest --parallel --coverage --min=100", | ||
"test": [ | ||
"@test:lint", | ||
"@test:refactor", | ||
"@test:types", | ||
"@test:type-coverage", | ||
"@test:unit" | ||
] | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,7 @@ | ||
parameters: | ||
level: max | ||
paths: | ||
- src | ||
- types | ||
|
||
reportUnmatchedIgnoredErrors: true |
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" | ||
colors="true" | ||
cacheDirectory=".phpunit.cache"> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory suffix=".php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
use Rector\Set\ValueObject\SetList; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__.'/src', | ||
]); | ||
|
||
$rectorConfig->rules([ | ||
InlineConstructorDefaultToPropertyRector::class, | ||
]); | ||
|
||
$rectorConfig->sets([ | ||
LevelSetList::UP_TO_PHP_82, | ||
SetList::CODE_QUALITY, | ||
SetList::DEAD_CODE, | ||
SetList::EARLY_RETURN, | ||
SetList::TYPE_DECLARATION, | ||
SetList::PRIVATIZATION, | ||
]); | ||
}; |
Oops, something went wrong.