Permalink
Browse files

[implements #9069393] Replace optional NULL argument of Function::set…

…Package() with separate method
  • Loading branch information...
manuelpichler committed Feb 24, 2011
1 parent 2460410 commit 1282cdb22d4f38f872e29fb2b0ace2bc159512ac
@@ -48,7 +48,7 @@
// PEAR/svn workaround
if (strpos('@php_bin@', '@php_bin') === 0) {
set_include_path('.' . PATH_SEPARATOR . dirname(__FILE__) . '/src/main/php');
set_include_path('.' . PATH_SEPARATOR . dirname(__FILE__) . '/../main/php');
}
require_once 'PHP/Depend/Autoload.php';
@@ -592,16 +592,28 @@ public function getPackage()
*
* @return void
*/
public function setPackage(PHP_Depend_Code_Package $package = null)
public function setPackage(PHP_Depend_Code_Package $package)
{
$this->_package = $package;
if (is_object($package)) {
$this->_package = $package;
$this->packageName = $package->getName();
} else {
$this->packageName = null;
$this->unsetPackage();
}
}
/**
* Resets the associated package reference.
*
* @return void
* @since 0.10.2
*/
public function unsetPackage()
{
$this->_package = null;
$this->packageName = null;
}
/**
* This method will return <b>true</b> when this class or interface instance
* was restored from the cache and not currently parsed. Otherwise this
@@ -125,14 +125,25 @@ public function getPackage()
public function setPackage(PHP_Depend_Code_Package $package = null)
{
if ($package === null) {
$this->packageName = null;
$this->_package = null;
$this->unsetPackage();
} else {
$this->packageName = $package->getName();
$this->_package = $package;
}
}
/**
* Resets the package associated with this function node.
*
* @return void
* @since 0.10.2
*/
public function unsetPackage()
{
$this->packageName = null;
$this->_package = null;
}
/**
* Returns the name of the parent namespace/package or <b>NULL</b> when this
* function does not belong to a package.
@@ -254,7 +254,7 @@ public function removeType(PHP_Depend_Code_AbstractClassOrInterface $type)
// Remove class from internal list
unset($this->types[$i]);
// Remove this as parent
$type->setPackage(null);
$type->unsetPackage();
}
}
@@ -302,7 +302,7 @@ public function removeFunction(PHP_Depend_Code_Function $function)
// Remove function from internal list
unset($this->functions[$i]);
// Remove this as parent
$function->setPackage(null);
$function->unsetPackage();
}
}
@@ -681,18 +681,35 @@ public function testGetSetPackage()
}
/**
* testSetPackageAcceptsNullAndResetsPackageReference
* testUnsetPackageResetsPackageReference
*
* @return void
*/
public function testSetPackageAcceptsNullAndResetsPackageReference()
public function testUnsetPackageResetsPackageReference()
{
$class = new PHP_Depend_Code_Class(__CLASS__);
$class->setPackage(new PHP_Depend_Code_Package(__FUNCTION__));
$class->setPackage(null);
$class->unsetPackage();
self::assertNull($class->getPackage());
}
/**
* testUnsetPackageResetsPackageNameProperty
*
* @return void
* @since 0.10.2
*/
public function testUnsetPackageResetsPackageNameProperty()
{
$class = new PHP_Depend_Code_Class(__CLASS__);
$class->setPackage(new PHP_Depend_Code_Package(__FUNCTION__));
$class->unsetPackage();
self::assertNull($class->getPackageName());
}
/**
* Tests that {@link PHP_Depend_Code_Class::getInterfaces()}
@@ -223,37 +223,39 @@ public function testGetPackageReturnsNullByDefault()
}
/**
* testGetStaticVariablesReturnsMergeOfAllStaticVariables
* testUnsetPackageWithNullWillResetPreviousPackage
*
* @return void
* @group pdepend
* @group pdepend::code
* @group unittest
*/
public function testSetPackageWithNullWillResetPreviousPackage()
public function testUnsetPackageWithNullWillResetPreviousPackage()
{
$package = new PHP_Depend_Code_Package('package');
$function = new PHP_Depend_Code_Function('func');
$function->setPackage($package);
$function->setPackage(null);
$function->unsetPackage();
self::assertNull($function->getPackage());
}
/**
* testSetPackageWithNullWillResetPackageNameProperty
* testUnsetPackageWithNullWillResetPackageNameProperty
*
* @return void
* @group pdepend
* @group pdepend::code
* @group unittest
*/
public function testSetPackageWithNullWillResetPackageNameProperty()
public function testUnsetPackageWithNullWillResetPackageNameProperty()
{
$function = new PHP_Depend_Code_Function(__FUNCTION__);
$function->setPackage(new PHP_Depend_Code_Package(__FUNCTION__));
$function->setPackage(null);
self::assertNull($function->getPackage());
$function->unsetPackage();
self::assertNull($function->getPackageName());
}
/**

0 comments on commit 1282cdb

Please sign in to comment.