Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9dfb9a0

Browse files
Merge remote-tracking branch 'origin/0.12.x-merge-up-into-0.13.x_602c2c500598c9.67242166' into 0.13.x
# Conflicts: # CHANGELOG.md
2 parents 2fee9b7 + 79dd990 commit 9dfb9a0

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

‎CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ All notable changes to this project will be documented in this file, in reverse
2424

2525
- Nothing.
2626

27+
## 0.12.2 - 2021年02月16日
28+
29+
30+
-----
31+
32+
### Release Notes for [0.12.2](https://github.com/open-code-modeling/php-code-ast/milestone/29)
33+
34+
0.12.x bugfix release (patch)
35+
36+
### 0.12.2
37+
38+
- Total issues resolved: **1**
39+
- Total pull requests resolved: **0**
40+
- Total contributors: **1**
41+
42+
#### bug
43+
44+
- [71: Typed is not considered via setTyped() method in ClassPropertyBuilder](https://github.com/open-code-modeling/php-code-ast/issues/71) thanks to @sandrokeil
45+
2746
## 0.12.1 - 2021年02月15日
2847

2948

‎README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ PHP code generation based on AST.
55
## Installation
66

77
```bash
8-
$ composer require open-code-modeling/php-code-ast --dev
8+
$ composer require open-code-modeling/php-code-ast
99
```
1010

1111
## Usage
1212

1313
> See unit tests in `tests` folder for comprehensive examples.
1414
15-
Let's start with a straightforward example of generating a class with the `ClassFactory`:
15+
Let's start with a straightforward example of generating a class with the `ClassBuilder`:
1616

1717
```php
1818
<?php
@@ -22,16 +22,16 @@ $printer = new PhpParser\PrettyPrinter\Standard(['shortArraySyntax' => true]);
2222

2323
$ast = $parser->parse('');
2424

25-
$classFactory = OpenCodeModeling\CodeAst\Builder\ClassBuilder::fromScratch('TestMy\\Awesome\\Service');
26-
$classFactory
25+
$classBuilder = OpenCodeModeling\CodeAst\Builder\ClassBuilder::fromScratch('TestClass', 'My\\Awesome\\Service');
26+
$classBuilder
2727
->setFinal(true)
2828
->setExtends('BaseClass')
2929
->setNamespaceImports('Foo\\Bar')
3030
->setImplements('\\Iterator', 'Bar');
3131

3232
$nodeTraverser = new PhpParser\NodeTraverser();
3333

34-
$classFactory->injectVisitors($nodeTraverser, $parser);
34+
$classBuilder->injectVisitors($nodeTraverser, $parser);
3535

3636
print_r($printer->prettyPrintFile($nodeTraverser->traverse($ast)));
3737
```
@@ -93,12 +93,15 @@ Now, change the body of the `toInt()` method to something else. You will see tha
9393

9494
### Reverse usage
9595

96-
It is also possible to create a factory class from parsed PHP AST. You can create an instance of `OpenCodeModeling\CodeAst\Factory\ClassFactory` by
97-
calling `OpenCodeModeling\CodeAst\Factory\ClassFactory::fromNodes()`.
96+
It is also possible to create a factory class from parsed PHP AST. You can create an instance of
97+
`OpenCodeModeling\CodeAst\Builder\ClassBuilder` by calling `OpenCodeModeling\CodeAst\Builder\ClassBuilder::fromNodes()`.
9898

9999
```php
100100
<?php
101-
$expected = <<<'EOF'
101+
$parser = (new PhpParser\ParserFactory())->create(PhpParser\ParserFactory::ONLY_PHP7);
102+
$printer = new PhpParser\PrettyPrinter\Standard(['shortArraySyntax' => true]);
103+
104+
$expected = <<<'EOF'
102105
<?php
103106

104107
declare (strict_types=1);
@@ -114,12 +117,11 @@ EOF;
114117

115118
$ast = $parser->parse($expected);
116119

117-
$classFactory = OpenCodeModeling\CodeAst\Builder\ClassBuilder::fromNodes(...$ast);
118-
119-
$classFactory->getName(); // TestClass
120-
$classFactory->getExtends(); // BaseClass
121-
$classFactory->isFinal(); // true
122-
$classFactory->isStrict(); // true
123-
$classFactory->isAbstract(); // false
120+
$classBuilder = OpenCodeModeling\CodeAst\Builder\ClassBuilder::fromNodes(...$ast);
124121

122+
$classBuilder->getName(); // TestClass
123+
$classBuilder->getExtends(); // BaseClass
124+
$classBuilder->isFinal(); // true
125+
$classBuilder->isStrict(); // true
126+
$classBuilder->isAbstract(); // false
125127
```

‎src/Builder/ClassPropertyBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public function setTyped(bool $typed): self
148148
{
149149
$this->typed = $typed;
150150

151+
$this->propertyGenerator->setTyped($typed);
152+
151153
return $this;
152154
}
153155

‎src/Code/PropertyGenerator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ public function setTypeDocBlockHint(?string $typeDocBlockHint): self
147147
return $this;
148148
}
149149

150+
public function setTyped(bool $typed): self
151+
{
152+
$this->typed = $typed;
153+
154+
return $this;
155+
}
156+
157+
public function isTyped(): bool
158+
{
159+
return $this->typed;
160+
}
161+
150162
public function generate(): Property
151163
{
152164
return new Property(

‎tests/Code/PropertyGeneratorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public function setUp(): void
4141
*/
4242
public function it_generates_property_with_doc_block(): void
4343
{
44-
$property = new PropertyGenerator('sourceFolder', 'string', false);
44+
$property = new PropertyGenerator('sourceFolder', 'string');
45+
$property->setTyped(false);
4546
$property->setDocBlockComment('source folder');
4647

4748
$expectedOutput = <<<'EOF'
@@ -63,7 +64,8 @@ public function it_generates_property_with_doc_block(): void
6364
*/
6465
public function it_generates_property_with_overridden_doc_block(): void
6566
{
66-
$property = new PropertyGenerator('sourceFolder', 'string', false);
67+
$property = new PropertyGenerator('sourceFolder', 'string', true);
68+
$property->setTyped(false);
6769
$property->setDocBlockComment('source folder');
6870
$property->overrideDocBlock(new DocBlock('Awesome'));
6971

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /