Skip to content

Commit 4d85332

Browse files
committed
Merge branch 'release/4.0.0'
2 parents 234a033 + c728cf4 commit 4d85332

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+980
-829
lines changed

.php_cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ $finder = PhpCsFixer\Finder::create()
66
->in(__DIR__);
77

88
return PhpCsFixer\Config::create()
9-
->setUsingCache(false)
10-
->setRules([
11-
'@PSR2' => true,
12-
'array_syntax' => [
13-
'syntax' => 'short',
14-
],
15-
'binary_operator_spaces' => true,
16-
'no_whitespace_in_blank_line' => true,
17-
'ternary_operator_spaces' => true,
18-
'cast_spaces' => true,
19-
'trailing_comma_in_multiline_array' => true
20-
])
9+
->setUsingCache(false)
10+
->setRules(array(
11+
'@PhpCsFixer' => true,
12+
))
2113
->setFinder($finder);

CHANGELOG.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# CHANGELOG
22

3+
## 4.0.0 - 2021/02/04
4+
- issue #11 - Allow class property to be typed
5+
- Clear, refactor and review code
6+
- Introduce `AccessRestrictedElementInterface`, `AssignedValueElementInterface` and `TypeHintedElementInterface`
7+
- Introduce `AccessRestrictedElementTrait`, `AssignedValueElementTrait` and `TypeHintedElementTrait`
8+
- Version 3.0 is no more maintained
9+
310
## 3.0.2 - 2021/01/28
411
- Update Travis CI badge and settings
512

613
## 3.0.1 - 2021/01/26
714
- Fix typo
815

916
## 3.0.0 - 2021/01/26
10-
- use `splitbrain/phpfarm:jessie` as Docker image and fix docker image settings
17+
- Use `splitbrain/phpfarm:jessie` as Docker image and fix docker image settings
1118
- Code requires PHP >= 7.4
1219
- Code cleaning
1320
- BC:
@@ -25,7 +32,7 @@
2532

2633
## 2.0.0
2734
- Use PHP 7.1 features
28-
- Refactore code
35+
- Refactor code
2936
- Fix typos
3037

3138
## 1.2.1
@@ -44,7 +51,7 @@
4451
- First major release
4552

4653
## 1.0.0RC01
47-
- Major: update source code structure, put Component and Element fodlers under ```src``` fodler, update composer and phpunit accordingly
54+
- Major: update source code structure, put Component and Element folders under ```src``` folder, update composer and phpunit accordingly
4855

4956
## 0.0.16
5057
- Minor: correct annotation
@@ -62,13 +69,13 @@
6269
- Refactoring : Use statements and Namespace are contained by a file not a class as each element should only knows what it contains not what that is around itself.
6370

6471
## 0.0.11
65-
- Issue : allow backslash within class name for namespace
72+
- Issue : allow a backslash within class name for namespace
6673

6774
## 0.0.10
68-
- Allow to provide annotation max length to use
75+
- Allow providing annotation max length to use
6976

7077
## 0.0.9
71-
- Fix issue : within a class, the additonal multi lines are not indented correcly
78+
- Fix issue : within a class, the additional multi lines are not indented correctly
7279

7380
## 0.0.8
7481
- Fix issue: workaround for known var_export issue with float value
@@ -80,7 +87,7 @@
8087
- Improvement: improve lisiblity and extensibility for PhpVariable and PhpFunctionParameter
8188

8289
## 0.0.5
83-
- Fix issue: function parameter type is not tooken into account
90+
- Fix issue: function parameter type is not token into account
8491

8592
## 0.0.4
8693
- Fix issue regarding property/variable that has no value but always has a null value assigned with an assignment sign

UPGRADE-4.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# UPGRADE FROM 3.* to 4.*
2+
3+
The main change is that `PhpProperty` are now type hinted in addition to internal methods removal and introduction of Interfaces and Traits
4+
- `WsdlToPhp\PhpGenerator\Element\PhpProperty::__construct` has a new parameter in the end named `$type` which can be any of the regular PHP types, or any existing PHP class or a PhpClass element or a string or a null value
5+
6+
Apart from that, the usage did not change, the inner classes has changed which should not be an issue if you did not inherit from them. Otherwise, launch your unit tests ;).

src/Component/AbstractComponent.php

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
use InvalidArgumentException;
88
use WsdlToPhp\PhpGenerator\Element\AbstractElement;
9-
use WsdlToPhp\PhpGenerator\Element\PhpFile as PhpFileElement;
9+
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock as PhpAnnotationBlockElement;
1010
use WsdlToPhp\PhpGenerator\Element\PhpClass as PhpClassElement;
1111
use WsdlToPhp\PhpGenerator\Element\PhpConstant as PhpConstantElement;
12-
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock as PhpAnnotationBlockElement;
12+
use WsdlToPhp\PhpGenerator\Element\PhpFile as PhpFileElement;
1313

1414
abstract class AbstractComponent implements GenerateableInterface
1515
{
1616
/**
17-
* @var PhpFileElement|PhpClassElement
17+
* @var PhpClassElement|PhpFileElement
1818
*/
1919
protected $mainElement;
2020

@@ -25,19 +25,9 @@ public function __toString(): string
2525

2626
public function toString(): string
2727
{
28-
$content = [];
29-
foreach ($this->getElements() as $element) {
30-
$content[] = $this->getElementString($element);
31-
}
32-
33-
return implode('', $content);
28+
return (string) $this->mainElement;
3429
}
3530

36-
/**
37-
* @return AbstractElement[]|string[]
38-
*/
39-
abstract public function getElements(): array;
40-
4131
public function setMainElement(AbstractElement $element): self
4232
{
4333
if ($element instanceof PhpFileElement || $element instanceof PhpClassElement) {
@@ -49,31 +39,6 @@ public function setMainElement(AbstractElement $element): self
4939
return $this;
5040
}
5141

52-
/**
53-
* @return PhpFileElement|PhpClassElement
54-
*/
55-
public function getMainElement(): AbstractElement
56-
{
57-
return $this->mainElement;
58-
}
59-
60-
/**
61-
* @throws InvalidArgumentException
62-
* @param string|AbstractElement $element
63-
* @return string
64-
*/
65-
protected function getElementString($element): string
66-
{
67-
$string = '';
68-
if (is_scalar($element)) {
69-
$string = $element;
70-
} elseif ($element instanceof AbstractElement) {
71-
$string = $element->toString();
72-
}
73-
74-
return $string;
75-
}
76-
7742
public function addConstantElement(PhpConstantElement $constant): self
7843
{
7944
if (!$constant->getClass() instanceof PhpClassElement && $this->mainElement instanceof PhpClassElement) {
@@ -85,10 +50,7 @@ public function addConstantElement(PhpConstantElement $constant): self
8550
}
8651

8752
/**
88-
* @param string $name
8953
* @param mixed $value
90-
* @param PhpClassElement|null $class
91-
* @return AbstractComponent
9254
*/
9355
public function addConstant(string $name, $value = null, ?PhpClassElement $class = null): self
9456
{
@@ -103,13 +65,19 @@ public function addAnnotationBlockElement(PhpAnnotationBlockElement $annotationB
10365
}
10466

10567
/**
106-
* @param array|string|PhpAnnotationBlockElement $annotations
107-
* @return AbstractComponent
68+
* @param array|PhpAnnotationBlockElement|string $annotations
10869
*/
10970
public function addAnnotationBlock($annotations): self
11071
{
11172
return $this->addAnnotationBlockElement(new PhpAnnotationBlockElement(is_array($annotations) ? $annotations : [
11273
$annotations,
11374
]));
11475
}
76+
77+
public function addString(string $string = ''): self
78+
{
79+
$this->mainElement->addChild($string);
80+
81+
return $this;
82+
}
11583
}

src/Component/GenerateableInterface.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ interface GenerateableInterface
88
{
99
const BREAK_LINE_CHAR = "\n";
1010

11+
public function __toString(): string;
12+
1113
/**
12-
* Must return the strict representation for the current element
13-
* @return string
14+
* Must return the strict representation for the current element.
1415
*/
1516
public function toString(): string;
16-
17-
public function __toString(): string;
1817
}

src/Component/PhpClass.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,37 @@
55
namespace WsdlToPhp\PhpGenerator\Component;
66

77
use WsdlToPhp\PhpGenerator\Element\PhpClass as PhpClassElement;
8-
use WsdlToPhp\PhpGenerator\Element\PhpProperty as PhpPropertyElement;
98
use WsdlToPhp\PhpGenerator\Element\PhpMethod as PhpMethodElement;
9+
use WsdlToPhp\PhpGenerator\Element\PhpProperty as PhpPropertyElement;
1010

1111
class PhpClass extends AbstractComponent
1212
{
13-
/**
14-
* @param string $name
15-
* @param bool $abstract
16-
* @param string|null $extends
17-
* @param array $interfaces
18-
*/
1913
public function __construct(string $name, bool $abstract = false, ?string $extends = null, array $interfaces = [])
2014
{
2115
$this->setMainElement(new PhpClassElement($name, $abstract, $extends, $interfaces));
2216
}
2317

24-
public function addMethodElement(PhpMethodElement $method): AbstractComponent
18+
public function addMethodElement(PhpMethodElement $method): self
2519
{
2620
$this->mainElement->addChild($method);
21+
2722
return $this;
2823
}
2924

30-
public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): AbstractComponent
25+
public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): self
3126
{
3227
return $this->addMethodElement(new PhpMethodElement($name, $parameters, $returnType, $access, $abstract, $static, $final, $hasBody));
3328
}
3429

35-
public function addPropertyElement(PhpPropertyElement $property): AbstractComponent
30+
public function addPropertyElement(PhpPropertyElement $property): self
3631
{
3732
$this->mainElement->addChild($property);
3833

3934
return $this;
4035
}
4136

42-
public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC): AbstractComponent
43-
{
44-
return $this->addPropertyElement(new PhpPropertyElement($name, $value, $access));
45-
}
46-
47-
public function getElements(): array
37+
public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC, $type = null): self
4838
{
49-
return [
50-
$this->getMainElement(),
51-
];
39+
return $this->addPropertyElement(new PhpPropertyElement($name, $value, $access, $type));
5240
}
5341
}

src/Component/PhpFile.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace WsdlToPhp\PhpGenerator\Component;
66

7+
use WsdlToPhp\PhpGenerator\Component\PhpClass as PhpClassComponent;
8+
use WsdlToPhp\PhpGenerator\Component\PhpInterface as PhpInterfaceComponent;
79
use WsdlToPhp\PhpGenerator\Element\PhpDeclare;
810
use WsdlToPhp\PhpGenerator\Element\PhpFile as PhpFileElement;
9-
use WsdlToPhp\PhpGenerator\Element\PhpVariable as PhpVariableElement;
1011
use WsdlToPhp\PhpGenerator\Element\PhpFunction as PhpFunctionElement;
11-
use WsdlToPhp\PhpGenerator\Component\PhpClass as PhpClassComponent;
12-
use WsdlToPhp\PhpGenerator\Component\PhpInterface as PhpInterfaceComponent;
12+
use WsdlToPhp\PhpGenerator\Element\PhpVariable as PhpVariableElement;
1313

1414
class PhpFile extends AbstractComponent
1515
{
@@ -18,16 +18,6 @@ public function __construct(string $name)
1818
$this->setMainElement(new PhpFileElement($name));
1919
}
2020

21-
/**
22-
* @return PhpFileElement[]
23-
*/
24-
public function getElements(): array
25-
{
26-
return [
27-
$this->getMainElement(),
28-
];
29-
}
30-
3121
public function addClassComponent(PhpClassComponent $class): self
3222
{
3323
$this->mainElement->addChild($class->toString());
@@ -68,7 +58,7 @@ public function addFunction(string $name, array $parameters = []): self
6858

6959
public function addUse(string $use, string $as = null, bool $last = false): self
7060
{
71-
$expression = empty($as) ? "use %1\$s;%3\$s" : "use %1\$s as %2\$s;%3\$s";
61+
$expression = empty($as) ? 'use %1$s;%3$s' : 'use %1$s as %2$s;%3$s';
7262
$this->mainElement->addChild(sprintf($expression, $use, $as, $last ? self::BREAK_LINE_CHAR : ''));
7363

7464
return $this;
@@ -90,7 +80,7 @@ public function setNamespace(string $namespace): self
9080
{
9181
$this->mainElement->addChild(
9282
sprintf(
93-
"%snamespace %s;%s",
83+
'%snamespace %s;%s',
9484
self::BREAK_LINE_CHAR,
9585
$namespace,
9686
self::BREAK_LINE_CHAR

src/Component/PhpInterface.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace WsdlToPhp\PhpGenerator\Component;
66

77
use WsdlToPhp\PhpGenerator\Element\PhpInterface as PhpInterfaceElement;
8-
use WsdlToPhp\PhpGenerator\Element\PhpProperty as PhpPropertyElement;
98
use WsdlToPhp\PhpGenerator\Element\PhpMethod as PhpMethodElement;
9+
use WsdlToPhp\PhpGenerator\Element\PhpProperty as PhpPropertyElement;
1010

1111
class PhpInterface extends PhpClass
1212
{
@@ -15,25 +15,26 @@ public function __construct(string $name, bool $abstract = false, ?string $exten
1515
$this->setMainElement(new PhpInterfaceElement($name, $abstract, $extends, $interfaces));
1616
}
1717

18-
public function addMethodElement(PhpMethodElement $method): AbstractComponent
18+
public function addMethodElement(PhpMethodElement $method): self
1919
{
2020
if ($method->getHasBody()) {
2121
$method->setHasBody(false);
2222
}
23+
2324
return parent::addMethodElement($method);
2425
}
2526

26-
public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): AbstractComponent
27+
public function addMethod(string $name, array $parameters = [], ?string $returnType = null, string $access = PhpMethodElement::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true): self
2728
{
2829
return $this->addMethodElement(new PhpMethodElement($name, $parameters, $returnType, $access, $abstract, $static, $final, false));
2930
}
3031

31-
public function addPropertyElement(PhpPropertyElement $property): AbstractComponent
32+
public function addPropertyElement(PhpPropertyElement $property): self
3233
{
3334
return $this;
3435
}
3536

36-
public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC): AbstractComponent
37+
public function addProperty(string $name, $value = null, string $access = PhpPropertyElement::ACCESS_PUBLIC, $type = null): self
3738
{
3839
return $this;
3940
}

0 commit comments

Comments
 (0)