Skip to content

Commit a267869

Browse files
committed
Remove deprecated methods and static node visitor methods in favour of high level API - Close #55
1 parent 4ebd7e2 commit a267869

9 files changed

+66
-235
lines changed

src/Builder/ClassBuilder.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,6 @@ public function hasNamespaceImport(string $namespace): bool
212212
return isset($this->namespaceImports[$namespace]);
213213
}
214214

215-
/**
216-
* @deprecated Use setNamespaceImports()
217-
* @param string ...$namespaces
218-
* @return self
219-
*/
220-
public function setNamespaceUse(string ...$namespaces): self
221-
{
222-
return $this->setNamespaceImports(...$namespaces);
223-
}
224-
225215
/**
226216
* Replacing will not work on existing files
227217
*
@@ -274,16 +264,6 @@ public function hasTrait(string $trait): bool
274264
return isset($this->traits[$trait]);
275265
}
276266

277-
/**
278-
* @deprecated Use setTraits()
279-
* @param string ...$traits
280-
* @return self
281-
*/
282-
public function setUseTrait(string ...$traits): self
283-
{
284-
return $this->setTraits(...$traits);
285-
}
286-
287267
/**
288268
* Replacing will not work on existing files
289269
*
@@ -498,15 +478,6 @@ public function getImplements(): array
498478
return $this->implements;
499479
}
500480

501-
/**
502-
* @deprecated Use namespaceImports()
503-
* @return string[]
504-
*/
505-
public function getNamespaceUse(): array
506-
{
507-
return $this->namespaceImports;
508-
}
509-
510481
/**
511482
* @return string[]
512483
*/
@@ -515,15 +486,6 @@ public function getNamespaceImports(): array
515486
return $this->namespaceImports;
516487
}
517488

518-
/**
519-
* @deprecated Use getTraits()
520-
* @return string[]
521-
*/
522-
public function getUseTrait(): array
523-
{
524-
return $this->traits;
525-
}
526-
527489
/**
528490
* @return string[]
529491
*/
@@ -621,16 +583,6 @@ public function sortNamespaceImports(callable $sort): self
621583
return $this;
622584
}
623585

624-
/**
625-
* @deprecated Use sortNamespaceImports()
626-
* @param callable $sort
627-
* @return $this
628-
*/
629-
public function sortNamespaceUse(callable $sort): self
630-
{
631-
return $this->sortNamespaceImports($sort);
632-
}
633-
634586
/**
635587
* @param Parser $parser
636588
* @return NodeVisitor[]

src/Builder/ClassBuilderCollection.php

Lines changed: 0 additions & 126 deletions
This file was deleted.

src/Builder/ClassConstBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace OpenCodeModeling\CodeAst\Builder;
1212

1313
use OpenCodeModeling\CodeAst\Code\ClassConstGenerator;
14+
use OpenCodeModeling\CodeAst\Code\IdentifierGenerator;
1415
use OpenCodeModeling\CodeAst\NodeVisitor\ClassConstant;
1516
use PhpParser\Node;
1617
use PhpParser\NodeTraverser;
@@ -98,7 +99,12 @@ public function setPublic(): self
9899

99100
public function generate(): NodeVisitor
100101
{
101-
return ClassConstant::forClassConstant($this->name, $this->value, $this->visibility);
102+
return new ClassConstant(
103+
new IdentifierGenerator(
104+
$this->name,
105+
new ClassConstGenerator($this->name, $this->value, $this->visibility)
106+
)
107+
);
102108
}
103109

104110
public function injectVisitors(NodeTraverser $nodeTraverser): void

src/Builder/InterfaceBuilder.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,6 @@ public function hasNamespaceImport(string $namespace): bool
167167
return isset($this->namespaceImports[$namespace]);
168168
}
169169

170-
/**
171-
* @deprecated Use setNamespaceImports()
172-
* @param string ...$namespaces
173-
* @return self
174-
*/
175-
public function setNamespaceUse(string ...$namespaces): self
176-
{
177-
return $this->setNamespaceImports(...$namespaces);
178-
}
179-
180170
/**
181171
* Replacing will not work on existing files
182172
*
@@ -346,15 +336,6 @@ public function getExtends(): array
346336
return $this->extends;
347337
}
348338

349-
/**
350-
* @deprecated Use namespaceImports()
351-
* @return string[]
352-
*/
353-
public function getNamespaceUse(): array
354-
{
355-
return $this->namespaceImports;
356-
}
357-
358339
/**
359340
* @return string[]
360341
*/

src/NodeVisitor/ClassConstant.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace OpenCodeModeling\CodeAst\NodeVisitor;
1212

13-
use OpenCodeModeling\CodeAst\Code\ClassConstGenerator;
1413
use OpenCodeModeling\CodeAst\Code\IdentifierGenerator;
1514
use PhpParser\Node;
1615
use PhpParser\Node\Stmt\Class_;
@@ -29,19 +28,6 @@ public function __construct(IdentifierGenerator $lineGenerator)
2928
$this->lineGenerator = $lineGenerator;
3029
}
3130

32-
public static function forClassConstant(
33-
string $constantName,
34-
$constantValue,
35-
int $flags = ClassConstGenerator::FLAG_PUBLIC
36-
): ClassConstant {
37-
return new self(
38-
new IdentifierGenerator(
39-
$constantName,
40-
new ClassConstGenerator($constantName, $constantValue, $flags)
41-
)
42-
);
43-
}
44-
4531
public function afterTraverse(array $nodes): ?array
4632
{
4733
$newNodes = [];

src/NodeVisitor/Property.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ public function __construct(PropertyGenerator $propertyGenerator)
2929
$this->propertyGenerator = $propertyGenerator;
3030
}
3131

32-
public static function forClassProperty(
33-
string $name = null,
34-
string $type = null,
35-
$defaultValue = null,
36-
bool $typed = true,
37-
int $flags = PropertyGenerator::FLAG_PRIVATE
38-
): self {
39-
return new self(
40-
new PropertyGenerator($name, $type, $defaultValue, $typed, $flags)
41-
);
42-
}
43-
4432
public function afterTraverse(array $nodes): ?array
4533
{
4634
$newNodes = [];

tests/Builder/ClassBuilderCollectionTest.php renamed to tests/Builder/FileCollectionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
namespace OpenCodeModelingTest\CodeAst\Builder;
1212

1313
use OpenCodeModeling\CodeAst\Builder\ClassBuilder;
14-
use OpenCodeModeling\CodeAst\Builder\ClassBuilderCollection;
14+
use OpenCodeModeling\CodeAst\Builder\FileCollection;
1515
use PHPUnit\Framework\TestCase;
1616

17-
final class ClassBuilderCollectionTest extends TestCase
17+
final class FileCollectionTest extends TestCase
1818
{
1919
/**
2020
* @test
2121
*/
2222
public function it_adds_same_class_builder_not_twice(): void
2323
{
2424
$classBuilder = ClassBuilder::fromScratch('MyClass');
25-
$cut = ClassBuilderCollection::fromItems($classBuilder);
25+
$cut = FileCollection::fromItems($classBuilder);
2626
$this->assertCount(1, $cut);
2727

2828
$cut->add($classBuilder);
@@ -40,7 +40,7 @@ public function it_adds_and_removes_class_builder(): void
4040
$classBuilderWithoutNamespace = ClassBuilder::fromScratch('MyClass');
4141
$classBuilderNamespace = ClassBuilder::fromScratch('MyClass', 'MyNamespace');
4242

43-
$cut = ClassBuilderCollection::fromItems($classBuilderWithoutNamespace);
43+
$cut = FileCollection::fromItems($classBuilderWithoutNamespace);
4444
$this->assertCount(1, $cut);
4545

4646
$cut->add($classBuilderNamespace);
@@ -78,7 +78,7 @@ public function it_adds_anonymous_class_builder(): void
7878
{
7979
$classBuilder = ClassBuilder::fromScratch(null);
8080

81-
$cut = ClassBuilderCollection::fromItems($classBuilder);
81+
$cut = FileCollection::fromItems($classBuilder);
8282
$this->assertCount(1, $cut);
8383

8484
$items = $cut->items();

0 commit comments

Comments
 (0)