8000 completes hasSomething & removeSomething methods on the Classgenerator by basz · Pull Request #26 · zendframework/zend-code · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

completes hasSomething & removeSomething methods on the Classgenerator #26

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TraitUsageGenerator deprecation in 2.7. Use UsageGenerator instead
  • Loading branch information
basz committed Jan 14, 2016
commit ed190e17b40df410cd08c04130e609ab06a857e0
40 changes: 20 additions & 20 deletions src/Generator/ClassGenerator.php
< 8000 /tr> 8000
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class ClassGenerator extends AbstractGenerator
protected $methods = [];

/**
* @var TraitUsageGenerator Object to encapsulate trait usage logic
* @var UsageGenerator Object to encapsulate trait usage logic
*/
protected $traitUsageGenerator;
protected $usageGenerator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break


/**
* Build a Code Generation Php Object from a Class Reflection
Expand Down Expand Up @@ -232,7 +232,7 @@ public function __construct(
$methods = [],
$docBlock = null
) {
$this->traitUsageGenerator = new TraitUsageGenerator($this);
$this->usageGenerator = new UsageGenerator($this);

if ($name !== null) {
$this->setName($name);
Expand Down Expand Up @@ -712,7 +712,7 @@ public function getProperty($propertyName)
*/
public function addUse($use, $useAlias = null)
{
$this->traitUsageGenerator->addUse($use, $useAlias);
$this->usageGenerator->addUse($use, $useAlias);
return $this;
}

Expand All @@ -722,7 +722,7 @@ public function addUse($use, $useAlias = null)
*/
public function hasUse($use)
{
return $this->traitUsageGenerator->hasUse($use);
return $this->usageGenerator->hasUse($use);
}

/**
Expand All @@ -731,7 +731,7 @@ public function hasUse($use)
*/
public function removeUse($use)
{
$this->traitUsageGenerator->removeUse($use);
$this->usageGenerator->removeUse($use);
return $this;
}

Expand All @@ -741,7 +741,7 @@ public function removeUse($use)
*/
public function hasUseAlias($use)
{
return $this->traitUsageGenerator->hasUseAlias($use);
return $this->usageGenerator->hasUseAlias($use);
}

/**
Expand All @@ -750,7 +750,7 @@ public function hasUseAlias($use)
*/
public function removeUseAlias($use)
{
$this->traitUsageGenerator->removeUseAlias($use);
$this->usageGenerator->removeUseAlias($use);
return $this;
}

Expand All @@ -761,7 +761,7 @@ public function removeUseAlias($use)
*/
public function getUses()
{
return $this->traitUsageGenerator->getUses();
return $this->usageGenerator->getUses();
}


Expand Down Expand Up @@ -902,7 +902,7 @@ public function hasMethod($methodName)
*/
public function addTrait($trait)
{
$this->traitUsageGenerator->addTrait($trait);
$this->usageGenerator->addTrait($trait);
return $this;
}

Expand All @@ -911,7 +911,7 @@ public function addTrait($trait)
*/
public function addTraits(array $traits)
{
$this->traitUsageGenerator->addTraits($traits);
$this->usageGenerator->addTraits($traits);
return $this;
}

Expand All @@ -920,31 +920,31 @@ public function addTraits(array $traits)
*/
public function hasTrait($traitName)
{
return $this->traitUsageGenerator->hasTrait($traitName);
return $this->usageGenerator->hasTrait($traitName);
}

/**
* @inherit Zend\Code\Generator\TraitUsageInterface
*/
public function getTraits()
{
return $this->traitUsageGenerator->getTraits();
return $this->usageGenerator->getTraits();
}

/**
* @inherit Zend\Code\Generator\TraitUsageInterface
*/
public function removeTrait($traitName)
{
return $this->traitUsageGenerator->removeTrait($traitName);
return $this->usageGenerator->removeTrait($traitName);
}

/**
* @inherit Zend\Code\Generator\TraitUsageInterface
*/
public function addTraitAlias($method, $alias, $visibility = null)
{
$this->traitUsageGenerator->addTraitAlias($method, $alias, $visibility);
$this->usageGenerator->addTraitAlias($method, $alias, $visibility);
return $this;
}

Expand All @@ -953,15 +953,15 @@ public function addTraitAlias($method, $alias, $visibility = null)
*/
public function getTraitAliases()
{
return $this->traitUsageGenerator->getTraitAliases();
return $this->usageGenerator->getTraitAliases();
}

/**
* @inherit Zend\Code\Generator\TraitUsageInterface
*/
public function addTraitOverride($method, $traitsToReplace)
{
$this->traitUsageGenerator->addTraitOverride($method, $traitsToReplace);
$this->usageGenerator->addTraitOverride($method, $traitsToReplace);
return $this;
}

Expand All @@ -970,7 +970,7 @@ public function addTraitOverride($method, $traitsToReplace)
*/
public function removeTraitOverride($method, $overridesToRemove = null)
{
$this->traitUsageGenerator->removeTraitOverride($method, $overridesToRemove);
$this->usageGenerator->removeTraitOverride($method, $overridesToRemove);

return $this;
}
Expand All @@ -980,7 +980,7 @@ public function removeTraitOverride($method, $overridesToRemove = null)
*/
public function getTraitOverrides()
{
return $this->traitUsageGenerator->getTraitOverrides();
return $this->usageGenerator->getTraitOverrides();
}

/**
Expand Down Expand Up @@ -1060,7 +1060,7 @@ public function generate()
}

$output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;
$output .= $this->traitUsageGenerator->generate();
$output .= $this->usageGenerator->generate();

$constants = $this->getConstants();

Expand Down
4 changes: 1 addition & 3 deletions src/Generator/TraitUsageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
/**
* Class TraitUsageGenerator
*
* @todo rewrite $this->uses storage such that it easier to differentiate between the class and its alias for 3.0
* @todo pull this logic into ClassGenerator OR rename this class to UsageGenerator for 3.0
*
* @deprecated Deprecated in 2.7. Use UsageGenerator instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this was changed, to be honest: TraitUsageGenerator is very specific and clear, whereas UsageGenerator seems too generic, and may be confused with the use statements generator at namespace level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly why I believe t's name is too strict. The TraitUsageGenerator is being used to generate the use statements at the namespace level in addition to trait usage's.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SNAFU then :-(

IMO, the TraitUsageGenerator should be used for traits, and maybe the other one can be ImportGenerator or such...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. we should either acknowledge that the TraitUsageGenerator has more responsibilities that it's name suggest (via a rename) or the usage functionality (for imports) should be moved to either the ClassGenerator itself or to a new class like you are suggesting.

  • I think the best way forward is too create a new PR that introduces an ImportGenerator for 3.0 and simply finish this PR focussing on the has- and remove methods. This PR is getting bloated...
  • do you agree that this is worth pursuing for the next release (which is soon i believe)

* @package Zend\Code\Generator
*/
class TraitUsageGenerator extends AbstractGenerator
Expand Down
13 changes: 13 additions & 0 deletions src/Generator/UsageGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Code\Generator;

class UsageGenerator extends TraitUsageGenerator
{
}
0