Skip to content

Commit cf7b4c3

Browse files
authored
Improve (#6)
1 parent 037c3d1 commit cf7b4c3

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

.scrutinizer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ build:
1515
tests:
1616
stop_on_failure: true
1717
override:
18-
- php-scrutinizer-run --enable-security-analysis
19-
- make codestyle
2018
-
2119
command: make coverage
2220
idle_timeout: 1200
2321
coverage:
2422
file: 'build/coverage/clover.xml'
2523
format: 'php-clover'
24+
- php-scrutinizer-run --enable-security-analysis
25+
- make codestyle
2626
cache:
2727
directories:
2828
- ~/.composer

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
language: php
22

33
php:
4-
- '7.0'
54
- '7.1'
65
- '7.2'
6+
- '7.3'
77

88
env:
99
global:
1010
CI: 'true'
1111
TEST_OUTPUT_STYLE: 'pretty'
1212
PHPCS_REPORT_STYLE: 'full'
1313
COMPOSER_OPTIONS: '--optimize-autoloader'
14+
matrix:
15+
- SYMFONY_VERSION: '~3.0'
16+
- SYMFONY_VERSION: '~4.0'
1417

1518
sudo: false
1619

@@ -19,9 +22,10 @@ matrix:
1922

2023
before_install:
2124
# remove xdebug to speed up build
22-
- phpenv config-rm xdebug.ini
25+
- phpenv config-rm xdebug.ini || true
2326

2427
install:
28+
- composer require symfony/validator:$SYMFONY_VERSION
2529
- make build
2630
script:
2731
- make test-technical

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yoanm/jsonrpc-params-symfony-constraint-doc-sdk",
3-
"description": "Simple JSON-RPC params validator that use Symfony validator component",
3+
"description": "SDK to generate JSON-RPC documentation from symfony constraint",
44
"license": "MIT",
55
"type": "library",
66
"support": {
@@ -25,7 +25,7 @@
2525
}
2626
},
2727
"require": {
28-
"php": ">=7.0",
28+
"php": ">=7.1",
2929
"yoanm/jsonrpc-server-doc-sdk": "dev-release/1.0.0",
3030
"symfony/validator": "^3.0 || ^4.0"
3131
},

phpunit.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
processIsolation="false"
99

1010
stopOnRisky="true"
11-
processUncoveredFilesFromWhitelist="true"
12-
addUncoveredFilesFromWhitelist="true"
13-
checkForUnintentionallyCoveredCode="true"
1411

1512
stopOnError="true"
1613
stopOnFailure="true"

src/App/Helper/ConstraintPayloadDocHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public function appendPayloadDoc(TypeDoc $doc, Constraint $constraint)
5757
*/
5858
public function getTypeIfExist(Constraint $constraint)
5959
{
60-
return $this->getPayloadDocValue($constraint, self::PAYLOAD_DOCUMENTATION_TYPE_KEY);
60+
return $this->hasPayloadDoc($constraint)
61+
? $this->getPayloadDocValue($constraint, self::PAYLOAD_DOCUMENTATION_TYPE_KEY)
62+
: null
63+
;
6164
}
6265

6366
/**

src/Infra/Transformer/ConstraintToParamsDocTransformer.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,10 @@ public function __construct(
4646
*
4747
* @return TypeDoc
4848
*/
49-
public function transform(Constraint $constraint)
50-
{
51-
return $this->docFromConstraint($constraint);
52-
}
53-
54-
/**
55-
* @param Constraint $constraintOrConstraintList
56-
* @param string|int|null $paramNameOrIndex
57-
*
58-
* @return TypeDoc
59-
*/
60-
private function docFromConstraint(Constraint $constraint, $paramNameOrIndex = null)
49+
public function transform(Constraint $constraint) : TypeDoc
6150
{
6251
$constraintList = [$constraint];
6352
$constraintDoc = $this->docTypeHelper->guess($constraintList);
64-
if (null !== $paramNameOrIndex) {
65-
$constraintDoc->setName($paramNameOrIndex);
66-
}
6753

6854
foreach ($constraintList as $constraint) {
6955
$this->appendToDoc($constraintDoc, $constraint);
@@ -76,7 +62,7 @@ private function docFromConstraint(Constraint $constraint, $paramNameOrIndex = n
7662
* @param TypeDoc $doc
7763
* @param Constraint $constraint
7864
*/
79-
private function appendToDoc(TypeDoc $doc, Constraint $constraint)
65+
private function appendToDoc(TypeDoc $doc, Constraint $constraint) : void
8066
{
8167
if ($doc instanceof ArrayDoc && $constraint instanceof Assert\All) {
8268
$this->appendAllConstraintToDoc($doc, $constraint);
@@ -105,7 +91,7 @@ private function appendToDoc(TypeDoc $doc, Constraint $constraint)
10591
* @param TypeDoc $doc
10692
* @param Constraint $constraint
10793
*/
108-
private function appendCollectionDoc(TypeDoc $doc, Constraint $constraint)
94+
private function appendCollectionDoc(TypeDoc $doc, Constraint $constraint) : void
10995
{
11096
// If not a collection => give up
11197
if (!$doc instanceof CollectionDoc) {
@@ -115,7 +101,8 @@ private function appendCollectionDoc(TypeDoc $doc, Constraint $constraint)
115101
if ($constraint instanceof Assert\Collection) {
116102
foreach ($constraint->fields as $fieldName => $constraintOrConstrainList) {
117103
$doc->addSibling(
118-
$this->docFromConstraint($constraintOrConstrainList, $fieldName)
104+
$this->transform($constraintOrConstrainList)
105+
->setName($fieldName)
119106
);
120107
}
121108

@@ -128,7 +115,7 @@ private function appendCollectionDoc(TypeDoc $doc, Constraint $constraint)
128115
* @param TypeDoc $doc
129116
* @param Constraint $constraint
130117
*/
131-
private function appendValidItemListDoc(TypeDoc $doc, Constraint $constraint)
118+
private function appendValidItemListDoc(TypeDoc $doc, Constraint $constraint) : void
132119
{
133120
if ($constraint instanceof Assert\Choice) {
134121
if ($constraint->callback && is_callable($constraint->callback)) {
@@ -146,7 +133,7 @@ private function appendValidItemListDoc(TypeDoc $doc, Constraint $constraint)
146133
* @param ArrayDoc $doc
147134
* @param Assert\All $constraint
148135
*/
149-
private function appendAllConstraintToDoc(ArrayDoc $doc, Assert\All $constraint)
136+
private function appendAllConstraintToDoc(ArrayDoc $doc, Assert\All $constraint) : void
150137
{
151138
$itemDoc = $this->docTypeHelper->guess($constraint->constraints);
152139
foreach ($constraint->constraints as $subConstraint) {

tests/Functional/App/Helper/ConstraintPayloadDocHelper/getTypeIfExistTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ public function setUp()
2222
$this->helper = new ConstraintPayloadDocHelper();
2323
}
2424

25-
public function testShouldReturnNullIfNotDefined()
25+
public function testShouldReturnNullIfNoPayload()
26+
{
27+
$constraint = new Assert\Valid();
28+
29+
$this->assertNull($this->helper->getTypeIfExist($constraint));
30+
}
31+
32+
public function testShouldReturnNullIfTypeIsNotDefined()
2633
{
2734
$constraint = new Assert\Valid();
2835

0 commit comments

Comments
 (0)