Skip to content

Commit

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

on: [push]

jobs:
run-phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v5
- 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@v2
- uses: php-actions/composer@v5
- name: PHPStan Static Analysis source code
uses: php-actions/phpstan@v3
with:
configuration: ./phpstan.neon.dist
run-php-unit-tests:
needs: run-php-stan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v5
- 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@v2
- uses: php-actions/composer@v5
- 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
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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 mkdir -p /home/app
WORKDIR /home/app
COPY . /home/app
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Country vat format validator template description

## Implementation steps

1. Create repository use template for name: <ISO-3166-standard-alpha2-code>-vat-format-validator
2. Update composer.json **name** attribute: rocketfellows/<ISO-3166-standard-alpha2-code>-vat-format-validator
3. Update composer.json with autoload and autoload-dev sections by pattern:
```php
"autoload": {
"psr-4": {
"rocketfellows\\<ISO-3166-standard-alpha2-code>VatFormatValidator\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"rocketfellows\\<ISO-3166-standard-alpha2-code>VatFormatValidator\\tests\\": "tests/"
}
}
```
3. Run docker-deploy.sh
4. Implement unit test in test/unit directory
5. Implement direct validator

# Templated readme

# <Country> vat format validator

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

This component provides <Country> vat number format validator.

Implementation of interface **rocketfellows\CountryVatFormatValidatorInterface\CountryVatFormatValidatorInterface**

Depends on https://github.com/rocketfellows/country-vat-format-validator-interface

## Installation

```shell
composer require rocketfellows/<ISO-3166-standard-alpha2-code>-vat-format-validator
```

## Usage example

Valid <Country> vat number:

```php
$validator = new <Country>VatFormatValidator();
$validator->isValid('');
$validator->isValid('');
```

Returns:

```shell
true
true
```

Invalid <Country> vat number:

```php
$validator = new <Country>VatFormatValidator();
$validator->isValid('');
$validator->isValid('');
```

```shell
false
false
```

## 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>
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "rocketfellows/country-vat-format-validator-template",
"authors": [
{
"name": "Arslan Imamutdinov",
"email": "[email protected]"
}
],
"license": "MIT",
"require": {
"php": ">=7.4",
"rocketfellows/country-vat-format-validator-interface": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "^0.12.90",
"squizlabs/php_codesniffer": "3.6.2"
}
}
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.
16 changes: 16 additions & 0 deletions src/CountryVatFormatValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// TODO: set namespace

/**
* TODO: rename validator
*/
class CountryVatFormatValidator extends CountryVatFormatValidator
{
private const VAT_NUMBER_PATTERN = ''; // TODO: implement pattern

protected function isValidFormat(string $vatNumber): bool
{
return (bool) preg_match(self::VAT_NUMBER_PATTERN, $vatNumber);
}
}
Empty file added tests/.gitkeep
Empty file.
Empty file added tests/unit/.gitkeep
Empty file.
39 changes: 39 additions & 0 deletions tests/unit/CountryVatFormatValidatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

// TODO: set namespace
namespace unit;

class CountryVatFormatValidatorTest extends TestCase
{
/**
* TODO: set type
* @var
*/
private $validator;

/**
* TODO: setup validator for test
*/
protected function setUp(): void
{
$this->validator = new CountryVatFormatValidator();
}

/**
* @dataProvider getVatNumbersProvidedData
*/
public function testValidationResult(string $vatNumber, bool $isValid): void
{
$this->assertEquals($isValid, $this->validator->isValid($vatNumber));
}

public function getVatNumbersProvidedData(): array
{
return [
[
'vatNumber',
'isValid',
],
];
}
}

0 comments on commit 0b64c4d

Please sign in to comment.