Skip to content

Commit

Permalink
Scrutinizer issue fixes (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored Apr 6, 2021
1 parent 1377a93 commit 0c3f112
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 50 deletions.
55 changes: 25 additions & 30 deletions src/Phing/ComponentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,20 @@ class ComponentHelper

/**
* ComponentHelper constructor.
* @param Project $project
*/
public function __construct(Project $project)
{
$this->project = $project;
}

/**
* @param Project $project
* @return ComponentHelper
*/
public static function getComponentHelper(Project $project)
public static function getComponentHelper(Project $project): ComponentHelper
{
if (null === $project) {
return null;
}

/**
* @var ComponentHelper $componentHelper
*/
/** @var ComponentHelper $componentHelper */
$componentHelper = $project->getReference(self::COMPONENT_HELPER_REFERENCE);

if (null !== $componentHelper) {
Expand All @@ -92,7 +88,7 @@ public static function getComponentHelper(Project $project)
/**
* Initializes the default tasks and data types.
*/
public function initDefaultDefinitions()
public function initDefaultDefinitions(): void
{
$this->initDefaultTasks();
$this->initDefaultDataTypes();
Expand All @@ -107,7 +103,7 @@ public function initDefaultDefinitions()
* @param string $class the class path to use
* @param string $classpath the classpat to use
*/
public function addTaskDefinition($name, $class, $classpath = null)
public function addTaskDefinition($name, $class, $classpath = null): void
{
if ('' === $class) {
$this->project->log("Task {$name} has no class defined.", Project::MSG_ERR);
Expand All @@ -125,7 +121,7 @@ public function addTaskDefinition($name, $class, $classpath = null)
*
* @return array
*/
public function getTaskDefinitions()
public function getTaskDefinitions(): array
{
return $this->taskdefs;
}
Expand All @@ -137,7 +133,7 @@ public function getTaskDefinitions()
* @param string $typeClass the class to use
* @param string $classpath the classpath to use
*/
public function addDataTypeDefinition($typeName, $typeClass, $classpath = null)
public function addDataTypeDefinition($typeName, $typeClass, $classpath = null): void
{
if (!isset($this->typedefs[$typeName])) {
Phing::import($typeClass, $classpath);
Expand All @@ -150,10 +146,6 @@ public function addDataTypeDefinition($typeName, $typeClass, $classpath = null)

public static function getElementName(Project $p = null, $o = null, $brief = false)
{
//if ($p === null) {
// TODO Project::getProject($o)
//}

return null === $p
? self::getUnmappedElementName($o, $brief)
: self::getComponentHelper($p)->getElementName(null, $o, $brief);
Expand All @@ -164,7 +156,7 @@ public static function getElementName(Project $p = null, $o = null, $brief = fal
*
* @return array
*/
public function getDataTypeDefinitions()
public function getDataTypeDefinitions(): array
{
return $this->typedefs;
}
Expand All @@ -178,7 +170,7 @@ public function getDataTypeDefinitions()
*
* @return Task A task object
*/
public function createTask($taskType)
public function createTask(string $taskType)
{
try {
$classname = '';
Expand Down Expand Up @@ -223,11 +215,10 @@ public function createTask($taskType)
*
* @param string $conditionType
*
* @throws BuildException
*
* @return Condition
* @throws BuildException
*/
public function createCondition($conditionType)
public function createCondition(string $conditionType): ?Condition
{
try {
$classname = '';
Expand Down Expand Up @@ -262,12 +253,10 @@ public function createCondition($conditionType)
*
* @param string $typeName Type name
*
* @throws BuildException
* Exception
*
* @return object A datatype object
* @throws BuildException Exception
*/
public function createDataType($typeName)
public function createDataType(string $typeName)
{
try {
$cls = '';
Expand Down Expand Up @@ -313,7 +302,13 @@ public function initSubProject(ComponentHelper $helper): void
}
}

private static function getUnmappedElementName($c, $brief)
/**
* @param object|string $c
* @param $brief
* @return string
* @throws \ReflectionException
*/
private static function getUnmappedElementName($c, $brief): string
{
$clazz = new ReflectionClass($c);
$name = $clazz->getName();
Expand Down Expand Up @@ -342,7 +337,7 @@ private function createObject(string $classname)
return new $cls();
}

private function initDefaultTasks()
private function initDefaultTasks(): void
{
$taskdefs = Phing::getResourcePath('etc/default.tasks.properties');

Expand All @@ -365,7 +360,7 @@ private function initDefaultTasks()
}
}

private function initDefaultDataTypes()
private function initDefaultDataTypes(): void
{
$typedefs = Phing::getResourcePath('etc/default.types.properties');

Expand All @@ -387,7 +382,7 @@ private function initDefaultDataTypes()
}
}

private function initCustomTasks()
private function initCustomTasks(): void
{
$taskdefs = Phing::getResourcePath('custom.task.properties');

Expand All @@ -408,7 +403,7 @@ private function initCustomTasks()
}
}

private function initCustomDataTypes()
private function initCustomDataTypes(): void
{
$typedefs = Phing::getResourcePath('custom.type.properties');

Expand Down
14 changes: 7 additions & 7 deletions src/Phing/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function getGlobalFilterSet()
* @param string $value The new value of the property.
* Must not be <code>null</code>.
*/
public function setProperty($name, $value)
public function setProperty(string $name, $value): void
{
PropertyHelper::getPropertyHelper($this)->setProperty(null, $name, $value, true);
}
Expand All @@ -246,7 +246,7 @@ public function setProperty($name, $value)
*
* @since 2.0
*/
public function setNewProperty($name, $value)
public function setNewProperty(string $name, $value): void
{
PropertyHelper::getPropertyHelper($this)->setNewProperty(null, $name, $value);
}
Expand All @@ -262,7 +262,7 @@ public function setNewProperty($name, $value)
*
* @see setProperty()
*/
public function setUserProperty($name, $value)
public function setUserProperty(string $name, $value): void
{
PropertyHelper::getPropertyHelper($this)->setUserProperty(null, $name, $value);
}
Expand All @@ -280,22 +280,22 @@ public function setUserProperty($name, $value)
*
* @see setProperty()
*/
public function setInheritedProperty($name, $value)
public function setInheritedProperty(string $name, $value): void
{
PropertyHelper::getPropertyHelper($this)->setInheritedProperty(null, $name, $value);
}

/**
* Returns the value of a property, if it is set.
*
* @param string $name The name of the property.
* @param string|null $name The name of the property.
* May be <code>null</code>, in which case
* the return value is also <code>null</code>.
*
* @return string the property value, or <code>null</code> for no match
* @return mixed the property value, or <code>null</code> for no match
* or if a <code>null</code> name is provided
*/
public function getProperty($name)
public function getProperty(?string $name)
{
return PropertyHelper::getPropertyHelper($this)->getProperty(null, $name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Phing/PropertyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ public function setInheritedProperty($ns, string $name, string $value): void
* Returns the value of a property, if it is set. You can override
* this method in order to plug your own storage.
*
* @param string $ns the namespace for the property (currently not used)
* @param string $name The name of the property.
* @param string $ns the namespace for the property (currently not used)
* @param string|null $name The name of the property.
* May be <code>null</code>, in which case
* the return value is also <code>null</code>.
*
Expand Down
8 changes: 4 additions & 4 deletions tests/Phing/Io/DirectoryScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function testChildrenOfExcludedDirectory()

public function testAbsolute1()
{
$base = $this->getProject()->getBasedir();
$base = $this->getProjectDir();
$tmpdir = substr($this->replaceSeparator($base->getAbsolutePath()) . '/tmp', $base->getPrefixLength());
$prefix = substr($base->getAbsolutePath(), 0, $base->getPrefixLength());

Expand Down Expand Up @@ -272,7 +272,7 @@ public function testAbsolute1()

public function testAbsolute2()
{
$base = $this->getProject()->getBasedir();
$base = $this->getProjectDir();
$prefix = substr($base->getAbsolutePath(), 0, $base->getPrefixLength());

$this->executeTarget('setup');
Expand All @@ -287,7 +287,7 @@ public function testAbsolute2()

public function testAbsolute3()
{
$base = $this->getProject()->getBasedir();
$base = $this->getProjectDir();
$tmpdir = substr($this->replaceSeparator($base->getAbsolutePath()) . '/tmp', $base->getPrefixLength());
$prefix = substr($base->getAbsolutePath(), 0, $base->getPrefixLength());

Expand Down Expand Up @@ -315,7 +315,7 @@ public function testAbsolute3()

public function testAbsolute4()
{
$base = $this->getProject()->getBasedir();
$base = $this->getProjectDir();
$tmpdir = substr($this->replaceSeparator($base->getAbsolutePath()) . '/tmp', $base->getPrefixLength());
$prefix = substr($base->getAbsolutePath(), 0, $base->getPrefixLength());

Expand Down
1 change: 0 additions & 1 deletion tests/Phing/Support/BuildFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ protected function assertLogLineContaining(
*/
protected function assertNotInLogs(
string $message,
$priority = null,
$errormsg = "Unexpected string '%s' found in logs: %s"
) {
foreach ($this->logBuffer as $log) {
Expand Down
12 changes: 6 additions & 6 deletions tests/Phing/Task/System/AppendTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function test2()

public function test3()
{
$file = new File($this->getProject()->getBasedir(), $this->tempFile);
$file = new File($this->getProjectDir(), $this->tempFile);
if ($file->exists()) {
$file->delete();
}
Expand All @@ -85,12 +85,12 @@ public function testPath()
{
$this->test3();

$file = new File($this->getProject()->getBasedir(), $this->tempFile);
$file = new File($this->getProjectDir(), $this->tempFile);
$origSize = $file->length();

$this->executeTarget('testPath');

$file2 = new File($this->getProject()->getBasedir(), $this->tempFile2);
$file2 = new File($this->getProjectDir(), $this->tempFile2);
$newSize = $file2->length();

$this->assertEquals($origSize, $newSize);
Expand All @@ -100,12 +100,12 @@ public function testAppend()
{
$this->test3();

$file = new File($this->getProject()->getBasedir(), $this->tempFile);
$file = new File($this->getProjectDir(), $this->tempFile);
$origSize = $file->length();

$this->executeTarget('testAppend');

$file2 = new File($this->getProject()->getBasedir(), $this->tempFile2);
$file2 = new File($this->getProjectDir(), $this->tempFile2);
$newSize = $file2->length();

$this->assertEquals($origSize * 2, $newSize);
Expand All @@ -119,7 +119,7 @@ public function testFilter()
public function testNoOverwrite()
{
$this->executeTarget('testnooverwrite');
$file2 = new File($this->getProject()->getBasedir(), $this->tempFile2);
$file2 = new File($this->getProjectDir(), $this->tempFile2);
$size = $file2->length();
$this->assertEquals(0, $size);
}
Expand Down

0 comments on commit 0c3f112

Please sign in to comment.