Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mopolo committed Sep 30, 2020
0 parents commit 3d68b72
Show file tree
Hide file tree
Showing 14 changed files with 993 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.php text eol=lf

# Directories/files not distributed when using Composer option `--prefer-dist`
/.phpstorm.meta.php/ export-ignore
/docs/ export-ignore
/tests/ export-ignore

/.gitattributes export-ignore
/.gitignore export-ignore
/infection.json.dist export-ignore
/mkdocs.yml export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/phpinsights.php export-ignore
37 changes: 37 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

on: [ push, pull_request ]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest, windows-latest ]
php: [ 7.1, 7.2, 7.3, 7.4 ]
dependency-version: [ prefer-lowest, prefer-stable ]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
run: vendor/bin/phpunit
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
composer.lock
coverage
docs
phpunit.xml
psalm.xml
vendor
36 changes: 36 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "cuyz/magic-constant",
"description": "PHP Magic Constants, even more powerful than an Enum",
"keywords": [
"enum",
"magic constant",
"magic number"
],
"type": "library",
"license": "MIT",
"homepage": "https://github.com/CuyZ/MagicConstant",
"authors": [
{
"name": "Nathan Boiron",
"email": "[email protected]",
"homepage": "https://github.com/Mopolo",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.0"
},
"autoload": {
"psr-4": {
"CuyZ\\MagicConstant\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"CuyZ\\MagicConstant\\Tests\\": "tests"
}
},
"require-dev": {
"phpunit/phpunit": "^7.5"
}
}
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Tests suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
15 changes: 15 additions & 0 deletions src/Exception/InvalidFormatException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace CuyZ\MagicConstant\Exception;

use CuyZ\MagicConstant\MagicConstant;
use InvalidArgumentException;

final class InvalidFormatException extends InvalidArgumentException implements MagicConstantException
{
public function __construct(MagicConstant $magicConstant, string $format)
{
parent::__construct(sprintf('The format `%s` does not exist in `%s`', $format, get_class($magicConstant)));
}
}
14 changes: 14 additions & 0 deletions src/Exception/InvalidKeyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace CuyZ\MagicConstant\Exception;

use InvalidArgumentException;

final class InvalidKeyException extends InvalidArgumentException implements MagicConstantException
{
public function __construct(string $className, string $key)
{
parent::__construct(sprintf('The key `%s` does not exist in `%s`', $key, $className));
}
}
22 changes: 22 additions & 0 deletions src/Exception/InvalidValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);

namespace CuyZ\MagicConstant\Exception;

use InvalidArgumentException;

final class InvalidValueException extends InvalidArgumentException implements MagicConstantException
{
/**
* @param string $className
* @param mixed $value
*/
public function __construct(string $className, $value)
{
if (is_object($value)) {
$value = get_class($value);
}

parent::__construct(sprintf('The value `%s` does not exist in `%s`', (string)$value, $className));
}
}
8 changes: 8 additions & 0 deletions src/Exception/MagicConstantException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CuyZ\MagicConstant\Exception;

interface MagicConstantException
{

}
Loading

0 comments on commit 3d68b72

Please sign in to comment.