Skip to content

Commit

Permalink
Merge branch 'refs/heads/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedghanem00 committed May 18, 2024
2 parents 1a1b43a + 8ef6c0c commit 99b1f80
Show file tree
Hide file tree
Showing 37 changed files with 488 additions and 116 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.github/ export-ignore
/tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpstan.dist.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml.dist export-ignore

45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
- push
- pull_request

jobs:
tests:
name: Tests

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os:
- ubuntu-latest
- windows-latest

php-version:
- 8.2
- 8.3

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-values: memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On

- name: Install dependencies with Composer
run: composer install --prefer-dist --no-ansi --no-interaction --no-progress

- name: Run PHP-CS-Fixer in Linter Mode
run: composer run-script php-cs-fixer -- --dry-run --show-progress=dots --using-cache=no --verbose

- name: Run PHPStan
run: composer run-script phpstan

- name: Run test-suites
run: composer run-script test
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
tags:
- "**"

jobs:
create-release:
name: Create Release

runs-on: ubuntu-latest

permissions:
contents: write

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

- name: Determine tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.RELEASE_TAG }}
name: v${{ env.RELEASE_TAG }}
generateReleaseNotes: true

42 changes: 0 additions & 42 deletions .github/workflows/testing.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.phpunit.cache/
/composer.lock
/phpunit.xml
/.php-cs-fixer.cache
34 changes: 34 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/*
* This file is part of the TempNumberClient package.
*
* (c) Ahmed Ghanem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

$header = <<<EOF
This file is part of the TempNumberClient package.
(c) Ahmed Ghanem <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->ignoreVCSIgnored(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true
])
->setUsingCache(true)
->setRiskyAllowed(true)
->setFinder($finder);
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@
},

"require": {
"php": ">=8.2",
"symfony/http-client": "6.*",
"doctrine/collections": "2.*"
"php": "^8.2",
"symfony/http-client": "^6.0 || ^7.0",
"doctrine/collections": "^2.0"
},

"require-dev": {
"phpunit/phpunit": "dev-main",
"phpstan/phpstan": "1.10.x-dev"
"phpstan/phpstan": "1.10.x-dev",
"friendsofphp/php-cs-fixer": "^3.54"
},

"scripts": {
"test": "@php vendor/bin/phpunit",
"phpstan": "@php vendor/bin/phpstan analyse src tests"
"test": "vendor/bin/phpunit",
"phpstan": "vendor/bin/phpstan analyse",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix"
},

"minimum-stability": "stable"
Expand Down
11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Method ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\:\\:newFromErrorName\\(\\) should return static\\(ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\) but returns ahmedghanem00\\\\TempNumberClient\\\\Exception\\\\API\\\\APIException\\.$#"
count: 1
path: src/Exception/API/APIException.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 2
path: tests/Unit/ClientTest.php
11 changes: 11 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5

paths:
- src/
- tests/

reportUnmatchedIgnoredErrors: true
37 changes: 21 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ This file is part of the TempNumberClient package.
~
~ (c) Ahmed Ghanem <[email protected]>
~
~ For the full copyright and license information, please view the LICENSE
~ file that was distributed with this source code.
-->

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
failOnWarning="true">
<testsuites>
<testsuite name="unit">
<directory>tests/unit</directory>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

<php>
<env name="API_KEY" value="" force="true" />
<env name="BACKEND_SERVER" value="Mock" force="true" />
<env name="API_KEY" value="" force="true"/>
<env name="BACKEND_SERVER" value="Mock" force="true"/>
</php>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
17 changes: 13 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php declare(strict_types=1);
<?php
/*
* This file is part of the TempNumberClient package.
*
* (c) Ahmed Ghanem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
/*
* This file is part of the TempNumberClient package.
*
Expand Down Expand Up @@ -57,8 +67,7 @@ public function __construct(
string $apiKey,
?HttpClientInterface $httpClient = null,
TempNumberServer $backendServer = TempNumberServer::Production
)
{
) {
$this->setHttpClient($httpClient ?? HttpClient::create());
$this->setApiKey($apiKey);
$this->setBackendServer($backendServer);
Expand All @@ -79,7 +88,7 @@ public function setApiKey(#[\SensitiveParameter] string $apiKey): void
}

/**
* @param array<string, string|array> $options
* @param array<string, string|array|int> $options
* @return void
*/
public function applyHttpClientOptions(array $options): void
Expand Down
12 changes: 11 additions & 1 deletion src/Enum/ActivationStatus.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php declare(strict_types=1);
<?php
/*
* This file is part of the TempNumberClient package.
*
* (c) Ahmed Ghanem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
/*
* This file is part of the TempNumberClient package.
*
Expand Down
12 changes: 11 additions & 1 deletion src/Enum/Country.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php declare(strict_types=1);
<?php
/*
* This file is part of the TempNumberClient package.
*
* (c) Ahmed Ghanem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
/*
* This file is part of the TempNumberClient package.
*
Expand Down
12 changes: 11 additions & 1 deletion src/Enum/Service.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php declare(strict_types=1);
<?php
/*
* This file is part of the TempNumberClient package.
*
* (c) Ahmed Ghanem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
/*
* This file is part of the TempNumberClient package.
*
Expand Down
22 changes: 21 additions & 1 deletion src/Enum/TempNumberServer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php declare(strict_types=1);
<?php
/*
* This file is part of the TempNumberClient package.
*
* (c) Ahmed Ghanem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
/*
* This file is part of the TempNumberClient package.
*
Expand All @@ -15,4 +25,14 @@ enum TempNumberServer: string
case Production = 'https://tn-api.com/api/v1/';

case Mock = 'https://mock.temp-number.org/v1/';

public static function fromName(string $name): self
{
foreach (self::cases() as $status) {
if ($name === $status->name) {
return $status;
}
}
throw new \ValueError("$name is not a valid backing value for enum " . self::class);
}
}
Loading

0 comments on commit 99b1f80

Please sign in to comment.