Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arslanim committed May 4, 2023
0 parents commit bd35947
Show file tree
Hide file tree
Showing 23 changed files with 519 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI-CHECKS

on: [push]

jobs:
run-phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- name: PHPCS analyze
run: ./vendor/bin/phpcs -p -s --standard=phpcs.xml src tests
run-php-stan:
needs: run-phpcs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- name: PHPStan Static Analysis source code
uses: php-actions/phpstan@v3
with:
version: 1.10.14
configuration: ./phpstan.neon.dist
run-php-unit-tests:
needs: run-php-stan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- uses: php-actions/phpunit@v3
with:
version: 9.5.28
bootstrap: vendor/autoload.php
configuration: phpunit.xml
args: --coverage-text
run-assemble-php-unit-coverage:
needs: run-php-unit-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- name: Run PHPUnit Tests
uses: php-actions/phpunit@v3
with:
version: 9.5.28
php_extensions: xdebug
bootstrap: vendor/autoload.php
configuration: phpunit.xml
args: --coverage-text
env:
XDEBUG_MODE: coverage
- name: Generate test coverage badge
uses: timkrase/[email protected]
with:
report: ./clover.xml
coverage_badge_path: 'badge.svg'
push_badge: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
composer.phar
/vendor/
.idea
.phpunit.result.cache

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
zlib1g-dev \
libzip-dev \
unzip \
mc
RUN docker-php-ext-install zip
RUN pecl install xdebug-3.1.5
RUN docker-php-ext-enable xdebug
RUN mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# <Country> vat number format validators config

![Code Coverage Badge](./badge.svg)

This package provides a preconfigured configuration class for vat number format validators for <Country> country.
Is an extension of the package https://github.com/rocketfellows/specific-country-vat-number-format-validators-config.

## Installation

```shell
composer require rocketfellows/<country>-vat-number-format-validators-config
```

## Dependencies

- https://github.com/rocketfellows/specific-country-vat-number-format-validators-config v1.0.0;
- https://github.com/rocketfellows/<country>-vat-format-validator v1.0.0;

## References

- https://github.com/rocketfellows/country-vat-format-validator-interface
- https://github.com/arslanim/iso-standard-3166

## List of package components

- **_rocketfellows\<country>VatNumberFormatValidatorsConfig\<country>VatNumberFormatValidatorsConfig_** - preconfigured configuration class for vat number format validators for <Country> country;

## <country>VatNumberFormatValidatorsConfig description

A configuration class that provides a match for the vat number format validators for the country <country>.

Class interface:
- **_getCountry_** - returns <country> **_Country_** instance;
- **_getValidators_** - returns validators tuple

When initializing the default configuration, the **_getValidators_** function returns a tuple with a single validator - an instance of <country>VatFormatValidator.

```php
$config = new <country>VatNumberFormatValidatorsConfig();

$config->getCountry(); // returns <country> Country instance
$config->getValidators(); // returns CountryVatFormatValidators with one item - instance of <country>VatFormatValidator
```

You can override the default validator by initializing the configuration class object with a new default validator through the first parameter of the class constructor.
Attention - validator must implement interface **_CountryVatFormatValidatorInterface_**.

```php
$newDefaultValidator = new NewDefaultValidator(); // instance of CountryVatFormatValidatorInterface
$config = new <country>VatNumberFormatValidatorsConfig($newDefaultValidator); // initialize with new default validator

$config->getValidators(); // returns CountryVatFormatValidators with one item - $newDefaultValidator
```

You can add additional validators to the default validator via the second constructor parameter.

Attention - additional validators parameter must be instance of tuple **_CountryVatFormatValidators_**.
And each additional validator must implement interface **_CountryVatFormatValidatorInterface_**.

```php
$firstAdditionalValidator = new FirstAdditionalValidator(); // instance of CountryVatFormatValidatorInterface
$secondAdditionalValidator = new SecondAdditionalValidator(); // instance of CountryVatFormatValidatorInterface

$config = new <country>VatNumberFormatValidatorsConfig(
null,
(
new CountryVatFormatValidators(
$firstAdditionalValidator,
$secondAdditionalValidator
)
)
);

// returns CountryVatFormatValidators with three items:
// default preconfigured validator by default - instance of <country>VatFormatValidator
// $firstAdditionalValidator - from additional tuple
// $secondAdditionalValidator - from additional tuple
$config->getValidators();
```

You can also completely rebuild the configuration by passing the default validator and a tuple of additional validators to the config class constructor.

```php
$defaultValidator = new DefaultValidator(); // instance of CountryVatFormatValidatorInterface
$firstAdditionalValidator = new FirstAdditionalValidator(); // instance of CountryVatFormatValidatorInterface
$secondAdditionalValidator = new SecondAdditionalValidator(); // instance of CountryVatFormatValidatorInterface

$config = new <country>VatNumberFormatValidatorsConfig(
$defaultValidator,
(
new CountryVatFormatValidators(
$firstAdditionalValidator,
$secondAdditionalValidator
)
)
);

// returns CountryVatFormatValidators with three items:
// $defaultValidator from constructor first parameter
// $firstAdditionalValidator - from additional tuple
// $secondAdditionalValidator - from additional tuple
$config->getValidators();
```

More use case examples can be found in the package's unit tests.

## Contributing

Welcome to pull requests. If there is a major changes, first please open an issue for discussion.

Please make sure to update tests as appropriate.
16 changes: 16 additions & 0 deletions badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1648587867">
<project timestamp="1648587867">
<metrics files="0" loc="0" ncloc="0" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</project>
</coverage>
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// TODO: set name
"name": "rocketfellows/<country>-vat-number-format-validators-config",
"authors": [
{
"name": "Arslan Imamutdinov",
"email": "[email protected]"
}
],
"license": "MIT",
"require": {
"php": ">=7.4",
"rocketfellows/specific-country-vat-number-format-validators-config": "1.0.0",
// TODO: require vat format validator package
"rocketfellows/<country>-vat-format-validator": "1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "3.6.2",
"roave/security-advisories": "dev-latest"
},
"autoload": {
"psr-4": {
// TODO: set namespace
"rocketfellows\\<country>VatNumberFormatValidatorsConfig\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
// TODO: set namespace
"rocketfellows\\<country>VatNumberFormatValidatorsConfig\\tests\\": "tests/"
}
}
}
3 changes: 3 additions & 0 deletions docker-compose-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker-compose down
3 changes: 3 additions & 0 deletions docker-compose-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker-compose up -d
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3"
services:
php:
build:
dockerfile: Dockerfile
context: ./
volumes:
- ./:/home/app
5 changes: 5 additions & 0 deletions docker-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

docker-compose -f docker-compose.yml up -d && \
docker-compose exec php composer install && \
docker-compose exec php composer dump-autoload
5 changes: 5 additions & 0 deletions docker-run-checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

sh ./docker-run-phpcs.sh && \
sh ./docker-run-phpstan.sh && \
sh ./docker-run-unit-tests.sh
7 changes: 7 additions & 0 deletions docker-run-phpcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

echo "=================== PHPCS ==================="

eval "docker-compose exec php ./vendor/bin/phpcs -p -s --standard=phpcs.xml src tests"

echo "\n============================================="
7 changes: 7 additions & 0 deletions docker-run-phpstan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

echo "=================== PHPSTAN ==================="

eval "docker-compose exec php ./vendor/bin/phpstan analyse"

echo "\n============================================="
7 changes: 7 additions & 0 deletions docker-run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

echo "=================== UNIT-TESTS ==================="

eval "docker-compose exec php ./vendor/bin/phpunit --colors=always --verbose --testdox"

echo "\n============================================="
26 changes: 26 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ruleset name="base-coding-style">
<description>Base component coding style</description>

<rule ref="PSR12"/>

<rule ref="PSR2.Methods.MethodDeclaration.Underscore"/>

<rule ref="Generic.Formatting.SpaceAfterCast"/>

<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="300"/>
<property name="absoluteLineLimit" value="500"/>
</properties>
</rule>

<rule ref="Squiz.Scope.MethodScope"/>

<rule ref="Squiz.Classes.ValidClassName"/>

<rule ref="PEAR.Functions.ValidDefaultValue"/>

<rule ref="Zend.Files.ClosingTag"/>
</ruleset>
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5
paths:
- src
- tests
24 changes: 24 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<coverage cacheDirectory=".phpunit.cache/code-coverage" processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="clover.xml" />
</report>
</coverage>

<testsuites>
<testsuite name="default">
<directory>./tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
Empty file added src/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions src/CountryVatNumberFormatValidatorsConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

// TODO: namespace

use arslanimamutdinov\ISOStandard3166\Country;
use arslanimamutdinov\ISOStandard3166\ISO3166;
use rocketfellows\CountryVatFormatValidatorInterface\CountryVatFormatValidatorInterface;
use rocketfellows\SpecificCountryVatNumberFormatValidatorsConfig\SpecificCountryVatNumberFormatValidatorsConfig;

class CountryVatNumberFormatValidatorsConfig extends SpecificCountryVatNumberFormatValidatorsConfig
{
public function getCountry(): Country
{
return ISO3166::COUNTRY();
}

protected function getDefaultValidator(): CountryVatFormatValidatorInterface
{
return new CountryVatFormatValidator();
}
}
Empty file added tests/.gitkeep
Empty file.
Empty file added tests/unit/.gitkeep
Empty file.
Loading

0 comments on commit bd35947

Please sign in to comment.