-
Notifications
You must be signed in to change notification settings - Fork 79
completes hasSomething & removeSomething methods on the Classgenerator #26
Changes from 17 commits
3dd06ba
b48dbaa
0928fb1
e35bf2d
c5e0012
554e98d
0751564
d515195
fb2353b
d36400b
ebe746f
4a5c385
ed190e1
2b14fd6
4db8842
09968b5
6e7f0c6
3304e2c
3e74da8
00d9fbe
801e093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,23 @@ public function getExtendedClass() | |
return $this->extendedClass; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function hasExtentedClass() | ||
{ | ||
return !empty($this->extendedClass); | ||
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. if 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.
both null and "" should be false. This was present. I just reused... |
||
} | ||
|
||
/** | ||
* @return ClassGenerator | ||
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.
|
||
*/ | ||
public function removeExtentedClass() | ||
{ | ||
$this->setExtendedClass(null); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $implementedInterfaces | ||
* @return ClassGenerator | ||
|
@@ -447,9 +464,29 @@ public function getImplementedInterfaces() | |
return $this->implementedInterfaces; | ||
} | ||
|
||
/** | ||
* @param string $implementedInterface | ||
* @return bool | ||
*/ | ||
public function hasImplementedInterface($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 ClassGenerator | ||
*/ | ||
public function removeImplementedInterface($implementedInterface) | ||
{ | ||
if ($this->hasImplementedInterface($implementedInterface)) { | ||
unset($this->implementedInterfaces[array_search($implementedInterface, $this->implementedInterfaces)]); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $constantName | ||
* | ||
* @return PropertyGenerator|false | ||
*/ | ||
public function getConstant($constantName) | ||
|
@@ -469,6 +506,18 @@ public function getConstants() | |
return $this->constants; | ||
} | ||
|
||
/** | ||
* @param string $constantName | ||
* @return ClassGenerator | ||
*/ | ||
public function removeConstant($constantName) | ||
{ | ||
if ($this->hasConstant($constantName)) { | ||
unset($this->constants[$constantName]); | ||
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. Can actually always directly |
||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $constantName | ||
* @return bool | ||
|
@@ -667,6 +716,44 @@ public function addUse($use, $useAlias = null) | |
return $this; | ||
} | ||
|
||
/** | ||
* @param string $use | ||
* @return ClassGenerator | ||
*/ | ||
public function hasUse($use) | ||
{ | ||
return $this->traitUsageGenerator->hasUse($use); | ||
} | ||
|
||
/** | ||
* @param string $use | ||
* @return ClassGenerator | ||
*/ | ||
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 ClassGenerator | ||
*/ | ||
public function removeUseAlias($use) | ||
{ | ||
$this->traitUsageGenerator->removeUseAlias($use); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns the "use" classes | ||
* | ||
|
@@ -677,6 +764,19 @@ public function getUses() | |
return $this->traitUsageGenerator->getUses(); | ||
} | ||
|
||
|
||
/** | ||
* @param string $propertyName | ||
* @return ClassGenerator | ||
*/ | ||
public function removeProperty($propertyName) | ||
{ | ||
if ($this->hasProperty($propertyName)) { | ||
unset($this->properties[$propertyName]); | ||
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. Can always directly |
||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $propertyName | ||
* @return bool | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ public function __construct(ClassGenerator $classGenerator) | |
*/ | ||
public function addUse($use, $useAlias = null) | ||
{ | ||
$this->removeUse($use); | ||
|
||
if (! empty($useAlias)) { | ||
$use .= ' as ' . $useAlias; | ||
} | ||
|
@@ -64,6 +66,70 @@ public function getUses() | |
return array_values($this->uses); | ||
} | ||
|
||
/** | ||
* @param $use | ||
* @return bool | ||
*/ | ||
public function hasUse($use) | ||
{ | ||
foreach ($this->uses as $key => $value) { | ||
$parts = explode(' ', $value); | ||
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. Argh, the internal representation of this thing is stringly typed? :X ouch. 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 wish 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. yep |
||
if ($parts[0] === $use) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param $use | ||
* @return bool | ||
*/ | ||
public function hasUseAlias($use) | ||
{ | ||
foreach ($this->uses as $key => $value) { | ||
$parts = explode(' as ', $value); | ||
if ($parts[0] === $use and count($parts) == 2) { | ||
return true; | ||
} | ||
}; | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param $use | ||
* @return TraitUsageGenerator | ||
*/ | ||
public function removeUse($use) | ||
{ | ||
foreach ($this->uses as $key => $value) { | ||
$parts = explode(' ', $value); | ||
if ($parts[0] === $use) { | ||
unset($this->uses[$value]); | ||
} | ||
}; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param $use | ||
* @return TraitUsageGenerator | ||
*/ | ||
public function removeUseAlias($use) | ||
{ | ||
foreach ($this->uses as $key => $value) { | ||
$parts = explode(' as ', $value); | ||
if ($parts[0] === $use and count($parts) == 2) { | ||
unset($this->uses[$value]); | ||
} | ||
}; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inherit Zend\Code\Generator\TraitUsageInterface | ||
*/ | ||
|
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.
bool
(due to PHP7 compliance)