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 2fee9b7

Browse files
Merge remote-tracking branch 'origin/0.12.x-merge-up-into-0.13.x_602a78393aa0f9.70627591' into 0.13.x
# Conflicts: # CHANGELOG.md
2 parents 0350d5c + b96f331 commit 2fee9b7

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
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.1 - 2021年02月15日
28+
29+
30+
-----
31+
32+
### Release Notes for [0.12.1](https://github.com/open-code-modeling/php-code-ast/milestone/27)
33+
34+
0.12.x bugfix release (patch)
35+
36+
### 0.12.1
37+
38+
- Total issues resolved: **1**
39+
- Total pull requests resolved: **0**
40+
- Total contributors: **1**
41+
42+
#### bug
43+
44+
- [69: ClassPropertyBuilder with typed=false not working](https://github.com/open-code-modeling/php-code-ast/issues/69) thanks to @sandrokeil
45+
2746
## 0.12.0 - 2021年02月12日
2847

2948

‎src/Builder/ClassPropertyBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function fromNode(Node\Stmt\Property $node, bool $typed = true): s
8080
$self->type = $type;
8181
$self->visibility = $node->flags;
8282
$self->typed = $typed;
83-
$self->propertyGenerator = new PropertyGenerator($self->name, $self->type);
83+
$self->propertyGenerator = new PropertyGenerator($self->name, $self->type, $typed);
8484

8585
$defaultValue = $node->props[0]->default;
8686

@@ -129,7 +129,7 @@ public static function fromScratch(string $name, string $type, bool $typed = tru
129129
$self->type = $type;
130130
$self->typed = $typed;
131131
$self->visibility = ClassConstGenerator::FLAG_PRIVATE;
132-
$self->propertyGenerator = new PropertyGenerator($self->name, $self->type);
132+
$self->propertyGenerator = new PropertyGenerator($self->name, $self->type, $typed);
133133

134134
return $self;
135135
}

‎tests/Builder/ClassMethodBuilderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,37 @@ public function setActive() : void
412412

413413
$this->assertSame($expected, $this->printer->prettyPrintFile($nodeTraverser->traverse($this->parser->parse(''))));
414414
}
415+
416+
/**
417+
* @test
418+
*/
419+
public function it_generates_method_with_args_and_default_value(): void
420+
{
421+
$ast = $this->parser->parse('');
422+
423+
$methodBuilder = ClassMethodBuilder::fromScratch('setActive')->setReturnType('void');
424+
$methodBuilder->setParameters(ParameterBuilder::fromScratch('active', 'bool')->setDefaultValue(null));
425+
426+
$classFactory = ClassBuilder::fromScratch('TestClass', 'My\\Awesome\\Service');
427+
$classFactory->setMethods($methodBuilder);
428+
429+
$nodeTraverser = new NodeTraverser();
430+
$classFactory->injectVisitors($nodeTraverser, $this->parser);
431+
432+
$expected = <<<'EOF'
433+
<?php
434+
435+
declare (strict_types=1);
436+
namespace My\Awesome\Service;
437+
438+
class TestClass
439+
{
440+
public function setActive(bool $active = null) : void
441+
{
442+
}
443+
}
444+
EOF;
445+
446+
$this->assertSame($expected, $this->printer->prettyPrintFile($nodeTraverser->traverse($ast)));
447+
}
415448
}

‎tests/Builder/ClassPropertyBuilderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function it_generates_property_for_empty_class(): void
4545
$ast = $this->parser->parse('');
4646

4747
$classFactory = ClassBuilder::fromScratch('TestClass', 'My\\Awesome\\Service');
48-
$classFactory->setProperties(ClassPropertyBuilder::fromScratch('aggregateId', 'string'));
48+
$classFactory->setProperties(ClassPropertyBuilder::fromScratch('aggregateId', 'string', false));
4949

5050
$this->assertTrue($classFactory->hasProperty('aggregateId'));
5151

@@ -60,7 +60,10 @@ public function it_generates_property_for_empty_class(): void
6060
6161
class TestClass
6262
{
63-
private string $aggregateId;
63+
/**
64+
* @var string
65+
*/
66+
private $aggregateId;
6467
}
6568
EOF;
6669

‎tests/Code/PropertyGeneratorTest.php

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

4747
$expectedOutput = <<<'EOF'
@@ -52,7 +52,7 @@ public function it_generates_property_with_doc_block(): void
5252
*
5353
* @var string
5454
*/
55-
private string $sourceFolder;
55+
private $sourceFolder;
5656
EOF;
5757

5858
$this->assertSame($expectedOutput, $this->printer->prettyPrintFile([$property->generate()]));
@@ -63,7 +63,7 @@ public function it_generates_property_with_doc_block(): void
6363
*/
6464
public function it_generates_property_with_overridden_doc_block(): void
6565
{
66-
$property = new PropertyGenerator('sourceFolder', 'string');
66+
$property = new PropertyGenerator('sourceFolder', 'string', false);
6767
$property->setDocBlockComment('source folder');
6868
$property->overrideDocBlock(new DocBlock('Awesome'));
6969

@@ -73,7 +73,7 @@ public function it_generates_property_with_overridden_doc_block(): void
7373
/**
7474
* Awesome
7575
*/
76-
private string $sourceFolder;
76+
private $sourceFolder;
7777
EOF;
7878

7979
$this->assertSame($expectedOutput, $this->printer->prettyPrintFile([$property->generate()]));

0 commit comments

Comments
(0)

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