Skip to content

Commit

Permalink
[implements #9069393] Replace optional NULL argument of Function::set…
Browse files Browse the repository at this point in the history
…Package() with separate method
  • Loading branch information
manuelpichler committed Feb 24, 2011
1 parent 2460410 commit 1282cdb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/bin/pdepend.php
Expand Up @@ -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';
Expand Down
18 changes: 15 additions & 3 deletions src/main/php/PHP/Depend/Code/AbstractClassOrInterface.php
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/main/php/PHP/Depend/Code/Function.php
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/PHP/Depend/Code/Package.php
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
23 changes: 20 additions & 3 deletions src/test/php/PHP/Depend/Code/ClassTest.php
Expand Up @@ -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()}
Expand Down
16 changes: 9 additions & 7 deletions src/test/php/PHP/Depend/Code/FunctionTest.php
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 1282cdb

Please sign in to comment.