mirror of
https://github.com/retailcrm/url-validator.git
synced 2025-04-20 01:10:55 +00:00
Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
77e2d1e5bb | ||
610b1ae0b7 | |||
|
9f521b4cb8 | ||
|
bf3b06d2ab |
8 changed files with 170 additions and 38 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -14,7 +14,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['7.3', '7.4']
|
||||
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2']
|
||||
steps:
|
||||
- name: Check out code into the workspace
|
||||
uses: actions/checkout@v2
|
||||
|
@ -35,4 +35,4 @@ jobs:
|
|||
- name: Run tests
|
||||
run: composer run-script phpunit-ci
|
||||
- name: Coverage
|
||||
run: bash <(curl -s https://codecov.io/bash)
|
||||
run: bash <(curl -s https://codecov.io/bash)
|
||||
|
|
18
.github/workflows/code_quality.yml
vendored
18
.github/workflows/code_quality.yml
vendored
|
@ -11,6 +11,9 @@ jobs:
|
|||
phpcs:
|
||||
name: "PHP CodeSniffer"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2']
|
||||
steps:
|
||||
- name: Check out code into the workspace
|
||||
uses: actions/checkout@v2
|
||||
|
@ -19,6 +22,9 @@ jobs:
|
|||
phpmd:
|
||||
name: "PHP MessDetector"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2']
|
||||
steps:
|
||||
- name: Check out code into the workspace
|
||||
uses: actions/checkout@v2
|
||||
|
@ -28,15 +34,19 @@ jobs:
|
|||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
level: 'warning'
|
||||
reporter: github-pr-check
|
||||
standard: './phpmd.xml'
|
||||
standard: './phpmd.xml.dist'
|
||||
target_directory: 'src'
|
||||
phpstan:
|
||||
name: PHPStan
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2']
|
||||
steps:
|
||||
- name: Check out code into the workspace
|
||||
uses: actions/checkout@v2
|
||||
- name: Run PHPStan
|
||||
uses: docker://oskarstark/phpstan-ga:0.12.88
|
||||
uses: docker://oskarstark/phpstan-ga:1.8.0
|
||||
with:
|
||||
args: analyse src -c phpstan.neon --memory-limit=1G --no-progress
|
||||
args: analyse src -c phpstan.neon --memory-limit=1G --no-progress
|
||||
|
||||
|
|
122
README.md
122
README.md
|
@ -1 +1,121 @@
|
|||
Validator for RetailCRM projects on Symfony
|
||||
[](https://github.com/retailcrm/url-validator/actions)
|
||||
[](https://codecov.io/gh/retailcrm/url-validator)
|
||||
[](https://packagist.org/packages/retailcrm/url-validator)
|
||||
[](https://packagist.org/packages/retailcrm/url-validator)
|
||||
|
||||
|
||||
# RetailCRM URL Validator
|
||||
|
||||
This validator will help you validate system URLs in your project using [`symfony/validator`](https://packagist.org/packages/symfony/validator).
|
||||
|
||||
# Table of contents
|
||||
|
||||
* [Requirements](#requirements)
|
||||
* [Installation](#installation)
|
||||
* [Usage](#usage)
|
||||
|
||||
## Requirements
|
||||
|
||||
* PHP 7.3 and above
|
||||
* PHP's JSON support
|
||||
* `symfony/validator`
|
||||
|
||||
## Installation
|
||||
|
||||
Follow those steps to install the library:
|
||||
|
||||
1. Download and install [Composer](https://getcomposer.org/download/) package manager.
|
||||
2. Install the library from the Packagist by executing this command:
|
||||
```bash
|
||||
composer require retailcrm/url-validator:"^1"
|
||||
```
|
||||
3. Include the autoloader if it's not included, or you didn't use Composer before.
|
||||
```php
|
||||
require 'path/to/vendor/autoload.php';
|
||||
```
|
||||
|
||||
Replace `path/to/vendor/autoload.php` with the correct path to Composer's `autoload.php`.
|
||||
|
||||
## Usage
|
||||
|
||||
You have to use Symfony Validator to work with this library.
|
||||
Please refer to the [official documentation for the `symfony/validator`](https://symfony.com/doc/current/components/validator.html) to learn how to use it.
|
||||
If you want to use `symfony/validator` with Symfony framework - you should use [this documentation](https://symfony.com/doc/current/validation.html).
|
||||
|
||||
After ensuring that you're using `symfony/validator` you can just append the `@CrmUrl()` annotation to the DTO entity field that contains system URL.
|
||||
|
||||
After that validator's `validate` call on this DTO will generate the proper violation messages for incorrect URLs.
|
||||
|
||||
Here's an example of the DTO (*note:* `@Assert\Url()` is optional):
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Dto;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use RetailCrm\Validator\CrmUrl;
|
||||
|
||||
class Connection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Url()
|
||||
* @CrmUrl()
|
||||
*/
|
||||
public $apiUrl;
|
||||
}
|
||||
```
|
||||
|
||||
And below you can find a complete example of usage (*note:* it requires `doctrine/annotations` and `symfony/cache` to work properly).
|
||||
|
||||
**Connection.php**
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use RetailCrm\Validator\CrmUrl;
|
||||
|
||||
class Connection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Url()
|
||||
* @CrmUrl()
|
||||
*/
|
||||
public $apiUrl;
|
||||
|
||||
public function __construct(string $apiUrl)
|
||||
{
|
||||
$this->apiUrl = $apiUrl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**app.php**
|
||||
```php
|
||||
namespace App;
|
||||
|
||||
// We assume that `app.php` is stored within a directory that is being autoloaded by Composer.
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
$validator = Validation::createValidatorBuilder()
|
||||
->enableAnnotationMapping(true)
|
||||
->addDefaultDoctrineAnnotationReader()
|
||||
->getValidator();
|
||||
$violations = $validator->validate(new Connection('https://test.retailcrm.pro'));
|
||||
|
||||
if (0 !== count($violations)) {
|
||||
foreach ($violations as $violation) {
|
||||
echo $violation->getMessage();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
"require": {
|
||||
"php": ">=7.3",
|
||||
"ext-json": "*",
|
||||
"symfony/validator": "^5.3"
|
||||
"symfony/validator": "^3 || ^4 || ^5 || ^6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5.7",
|
||||
"squizlabs/php_codesniffer": "3.*",
|
||||
"phpstan/phpstan": "^0.12.92",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpmd/phpmd": "^2.10"
|
||||
},
|
||||
"support": {
|
||||
|
@ -40,9 +40,9 @@
|
|||
"scripts": {
|
||||
"phpunit": "./vendor/bin/phpunit -c phpunit.xml.dist --coverage-text",
|
||||
"phpunit-ci": "@php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit --teamcity -c phpunit.xml.dist",
|
||||
"phpmd": "./vendor/bin/phpmd src text ./phpmd.xml",
|
||||
"phpcs": "./vendor/bin/phpcs -p src --runtime-set testVersion 7.3-8.0 && ./vendor/bin/phpcs -p tests --runtime-set testVersion 7.3-8.0 --warning-severity=0",
|
||||
"phpstan": "./vendor/bin/phpstan analyse -c phpstan.neon src --memory-limit=-1",
|
||||
"phpmd": "./vendor/bin/phpmd src text ./phpmd.xml.dist",
|
||||
"phpcs": "./vendor/bin/phpcs -p --standard=phpcs.xml.dist --runtime-set testVersion 7.3-8.2 --warning-severity=0",
|
||||
"phpstan": "./vendor/bin/phpstan analyse -c phpstan.neon",
|
||||
"verify": [
|
||||
"@phpcs",
|
||||
"@phpmd",
|
||||
|
|
|
@ -5,43 +5,43 @@
|
|||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<description>Ruleset</description>
|
||||
<rule ref="rulesets/controversial.xml" />
|
||||
<rule ref="rulesets/unusedcode.xml" />
|
||||
|
||||
<rule ref="rulesets/design.xml">
|
||||
<exclude name="CouplingBetweenObjects" />
|
||||
<rule ref="rulesets/controversial.xml"/>
|
||||
<rule ref="rulesets/design.xml"/>
|
||||
<rule ref="rulesets/naming.xml">
|
||||
<exclude name="ShortVariable" />
|
||||
<exclude name="LongVariable" />
|
||||
<exclude name="LongClassName" />
|
||||
<exclude name="ShortMethodName" />
|
||||
</rule>
|
||||
<rule ref="rulesets/cleancode.xml">
|
||||
<exclude name="StaticAccess" />
|
||||
<exclude name="ElseExpression" />
|
||||
</rule>
|
||||
<rule ref="rulesets/unusedcode.xml">
|
||||
<exclude name="UnusedFormalParameter" />
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml">
|
||||
<exclude name="TooManyPublicMethods" />
|
||||
<exclude name="TooManyFields" />
|
||||
</rule>
|
||||
<rule ref="rulesets/naming.xml">
|
||||
<exclude name="ShortVariable" />
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/naming.xml/ShortVariable">
|
||||
<properties>
|
||||
<property name="minimum" value="2" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
|
||||
<rule ref="rulesets/naming.xml/LongVariable">
|
||||
<properties>
|
||||
<property name="maxmethods" value="20" />
|
||||
<property name="maximum" value="30" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/TooManyFields">
|
||||
<rule ref="rulesets/naming.xml/LongClassName">
|
||||
<properties>
|
||||
<property name="maxfields" value="30" />
|
||||
<property name="maximum" value="80" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
|
||||
<rule ref="rulesets/naming.xml/ShortMethodName">
|
||||
<properties>
|
||||
<property name="maximum" value="15" />
|
||||
<property name="minimum" value="2" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<exclude-pattern>tests/*</exclude-pattern>
|
||||
</ruleset>
|
|
@ -6,3 +6,5 @@ parameters:
|
|||
paths:
|
||||
- src
|
||||
- tests
|
||||
bootstrapFiles:
|
||||
- ./vendor/autoload.php
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
<coverage>
|
||||
<include>
|
||||
<directory>src</directory>
|
||||
<directory>dev</directory>
|
||||
</include>
|
||||
<report>
|
||||
<clover outputFile="coverage.xml"/>
|
||||
|
|
|
@ -21,19 +21,20 @@ class CrmUrlValidatorTest extends TestCase
|
|||
public function testValidateSuccess(): void
|
||||
{
|
||||
$validCrms = [
|
||||
'https://asd.retailcrm.ru',
|
||||
'https://test.retailcrm.pro',
|
||||
'https://raisa.retailcrm.es',
|
||||
'https://blabla.simla.com',
|
||||
'https://blabla.simlachat.com',
|
||||
'https://blabla.simlachat.ru',
|
||||
'https://blabla.ecomlogic.com',
|
||||
'https://retailcrm.tvoydom.ru',
|
||||
'https://retailcrm.inventive.ru',
|
||||
'https://crm.baucenter.ru',
|
||||
'https://crm.holodilnik.ru',
|
||||
'https://crm.eco.lanit.ru',
|
||||
'https://ecom.inventive.ru',
|
||||
'https://retailcrm.tvoydom.ru',
|
||||
'https://test.retailcrm.ru',
|
||||
'https://test.retailcrm.pro',
|
||||
'https://test.retailcrm.es',
|
||||
'https://test.simla.com',
|
||||
'https://test.simlachat.com',
|
||||
'https://test.ecomlogic.com',
|
||||
'https://test.retailcrm.io',
|
||||
'https://test.simla.io'
|
||||
];
|
||||
|
||||
$translator = new class () implements TranslatorInterface, LocaleAwareInterface {
|
||||
|
|
Loading…
Add table
Reference in a new issue