This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
completes hasSomething & removeSomething methods on the Classgenerator #26
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3dd06ba
introduce removeProperty method
basz b48dbaa
add unittest
basz 0928fb1
introduce removeConstant method
basz e35bf2d
add unittest
basz c5e0012
introduce removeExtentedClass and hasExtentedClass methods
basz 554e98d
adds unittests
basz 0751564
introduces hasImplementedInterface and removeImplementedInterface met…
basz d515195
add unittests
basz fb2353b
introduce hasUse, removeUse, hasUseAlias, removeUseAlias methods with…
basz d36400b
add unitest
basz ebe746f
doc block note
basz 4a5c385
cleanup : docblock, leftover line and code styles
basz ed190e1
TraitUsageGenerator deprecation in 2.7. Use UsageGenerator instead
basz 2b14fd6
prevent addUse with different alias to be stored
basz 4db8842
Revert "TraitUsageGenerator deprecation in 2.7. Use UsageGenerator in…
basz 09968b5
mention added methods in docs
basz 6e7f0c6
Revert "doc block note"
basz 3304e2c
return types
basz 3e74da8
Can always directly unset(), no check needed
basz 00d9fbe
I would also check against \\ strings...
basz 801e093
cs
basz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ class ClassGenerator extends AbstractGenerator | |
* Build a Code Generation Php Object from a Class Reflection | ||
* | ||
* @param ClassReflection $classReflection | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public static function fromReflection(ClassReflection $classReflection) | ||
{ | ||
|
@@ -167,7 +167,7 @@ public static function fromReflection(ClassReflection $classReflection) | |
* | ||
* @throws Exception\InvalidArgumentException | ||
* @param array $array | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public static function fromArray(array $array) | ||
{ | ||
|
@@ -262,7 +262,7 @@ public function __construct( | |
|
||
/** | ||
* @param string $name | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setName($name) | ||
{ | ||
|
@@ -286,7 +286,7 @@ public function getName() | |
|
||
/** | ||
* @param string $namespaceName | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setNamespaceName($namespaceName) | ||
{ | ||
|
@@ -304,7 +304,7 @@ public function getNamespaceName() | |
|
||
/** | ||
* @param FileGenerator $fileGenerator | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setContainingFileGenerator(FileGenerator $fileGenerator) | ||
{ | ||
|
@@ -322,7 +322,7 @@ public function getContainingFileGenerator() | |
|
||
/** | ||
* @param DocBlockGenerator $docBlock | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setDocBlock(DocBlockGenerator $docBlock) | ||
{ | ||
|
@@ -340,7 +340,7 @@ public function getDocBlock() | |
|
||
/** | ||
* @param array|string $flags | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setFlags($flags) | ||
{ | ||
|
@@ -359,7 +359,7 @@ public function setFlags($flags) | |
|
||
/** | ||
* @param string $flag | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addFlag($flag) | ||
{ | ||
|
@@ -369,7 +369,7 @@ public function addFlag($flag) | |
|
||
/** | ||
* @param string $flag | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function removeFlag($flag) | ||
{ | ||
|
@@ -379,7 +379,7 @@ public function removeFlag($flag) | |
|
||
/** | ||
* @param bool $isAbstract | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setAbstract($isAbstract) | ||
{ | ||
|
@@ -396,7 +396,7 @@ public function isAbstract() | |
|
||
/** | ||
* @param bool $isFinal | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setFinal($isFinal) | ||
{ | ||
|
@@ -413,7 +413,7 @@ public function isFinal() | |
|
||
/** | ||
* @param string $extendedClass | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setExtendedClass($extendedClass) | ||
{ | ||
|
@@ -429,12 +429,33 @@ public function getExtendedClass() | |
return $this->extendedClass; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasExtentedClass() | ||
{ | ||
return !empty($this->extendedClass); | ||
} | ||
|
||
/** | ||
* @return self | ||
*/ | ||
public function removeExtentedClass() | ||
{ | ||
$this->setExtendedClass(null); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $implementedInterfaces | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function setImplementedInterfaces(array $implementedInterfaces) | ||
{ | ||
array_map(function ($implementedInterface) { | ||
return (string) TypeGenerator::fromTypeString($implementedInterface); | ||
}, $implementedInterfaces); | ||
|
||
$this->implementedInterfaces = $implementedInterfaces; | ||
return $this; | ||
} | ||
|
@@ -447,9 +468,29 @@ public function getImplementedInterfaces() | |
return $this->implementedInterfaces; | ||
} | ||
|
||
/** | ||
* @param string $implementedInterface | ||
* @return bool | ||
*/ | ||
public function hasImplementedInterface($implementedInterface) | ||
{ | ||
$implementedInterface = (string) TypeGenerator::fromTypeString($implementedInterface); | ||
return in_array($implementedInterface, $this->implementedInterfaces); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also check against |
||
} | ||
|
||
/** | ||
* @param $implementedInterface | ||
* @return self | ||
*/ | ||
public function removeImplementedInterface($implementedInterface) | ||
{ | ||
$implementedInterface = (string) TypeGenerator::fromTypeString($implementedInterface); | ||
unset($this->implementedInterfaces[array_search($implementedInterface, $this->implementedInterfaces)]); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $constantName | ||
* | ||
* @return PropertyGenerator|false | ||
*/ | ||
public function getConstant($constantName) | ||
|
@@ -469,6 +510,17 @@ public function getConstants() | |
return $this->constants; | ||
} | ||
|
||
/** | ||
* @param string $constantName | ||
* @return self | ||
*/ | ||
public function removeConstant($constantName) | ||
{ | ||
unset($this->constants[$constantName]); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $constantName | ||
* @return bool | ||
|
@@ -483,7 +535,7 @@ public function hasConstant($constantName) | |
* | ||
* @param PropertyGenerator $constant | ||
* @throws Exception\InvalidArgumentException | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addConstantFromGenerator(PropertyGenerator $constant) | ||
{ | ||
|
@@ -516,7 +568,7 @@ public function addConstantFromGenerator(PropertyGenerator $constant) | |
* | ||
* @throws Exception\InvalidArgumentException | ||
* | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addConstant($name, $value) | ||
{ | ||
|
@@ -537,7 +589,7 @@ public function addConstant($name, $value) | |
/** | ||
* @param PropertyGenerator[]|array[] $constants | ||
* | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addConstants(array $constants) | ||
{ | ||
|
@@ -556,7 +608,7 @@ public function addConstants(array $constants) | |
|
||
/** | ||
* @param array $properties | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addProperties(array $properties) | ||
{ | ||
|
@@ -582,7 +634,7 @@ public function addProperties(array $properties) | |
* @param string|array $defaultValue | ||
* @param int $flags | ||
* @throws Exception\InvalidArgumentException | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addProperty($name, $defaultValue = null, $flags = PropertyGenerator::FLAG_PUBLIC) | ||
{ | ||
|
@@ -608,7 +660,7 @@ public function addProperty($name, $defaultValue = null, $flags = PropertyGenera | |
* | ||
* @param PropertyGenerator $property | ||
* @throws Exception\InvalidArgumentException | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addPropertyFromGenerator(PropertyGenerator $property) | ||
{ | ||
|
@@ -659,14 +711,52 @@ public function getProperty($propertyName) | |
* | ||
* @param string $use | ||
* @param string|null $useAlias | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addUse($use, $useAlias = null) | ||
{ | ||
$this->traitUsageGenerator->addUse($use, $useAlias); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $use | ||
* @return self | ||
*/ | ||
public function hasUse($use) | ||
{ | ||
return $this->traitUsageGenerator->hasUse($use); | ||
} | ||
|
||
/** | ||
* @param string $use | ||
* @return self | ||
*/ | ||
public function removeUse($use) | ||
{ | ||
$this->traitUsageGenerator->removeUse($use); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $use | ||
* @return bool | ||
*/ | ||
public function hasUseAlias($use) | ||
{ | ||
return $this->traitUsageGenerator->hasUseAlias($use); | ||
} | ||
|
||
/** | ||
* @param $use | ||
* @return self | ||
*/ | ||
public function removeUseAlias($use) | ||
{ | ||
$this->traitUsageGenerator->removeUseAlias($use); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns the "use" classes | ||
* | ||
|
@@ -677,6 +767,18 @@ public function getUses() | |
return $this->traitUsageGenerator->getUses(); | ||
} | ||
|
||
|
||
/** | ||
* @param string $propertyName | ||
* @return self | ||
*/ | ||
public function removeProperty($propertyName) | ||
{ | ||
unset($this->properties[$propertyName]); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $propertyName | ||
* @return bool | ||
|
@@ -688,7 +790,7 @@ public function hasProperty($propertyName) | |
|
||
/** | ||
* @param array $methods | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addMethods(array $methods) | ||
{ | ||
|
@@ -716,7 +818,7 @@ public function addMethods(array $methods) | |
* @param string $body | ||
* @param string $docBlock | ||
* @throws Exception\InvalidArgumentException | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addMethod( | ||
$name = null, | ||
|
@@ -741,7 +843,7 @@ public function addMethod( | |
* | ||
* @param MethodGenerator $method | ||
* @throws Exception\InvalidArgumentException | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function addMethodFromGenerator(MethodGenerator $method) | ||
{ | ||
|
@@ -777,13 +879,11 @@ public function getMethod($methodName) | |
|
||
/** | ||
* @param string $methodName | ||
* @return ClassGenerator | ||
* @return self | ||
*/ | ||
public function removeMethod($methodName) | ||
{ | ||
if ($this->hasMethod($methodName)) { | ||
unset($this->methods[strtolower($methodName)]); | ||
} | ||
unset($this->methods[strtolower($methodName)]); | ||
|
||
return $this; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
empty()
is used to compare againstnull
, then usenull !== $this->extendedClass
instead, as an empty string would pass this check (and would be invalid)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both null and "" should be false.
This was present. I just reused...