Skip to content

Commit

Permalink
Fix some phpmd advisories (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 7, 2023
1 parent 841e805 commit 839f39f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -57,7 +57,7 @@ to create necessary methods with minimum code footprint::
// hasField, getField, removeField also can be added, see further docs.
}

Traits add multiple checks to prevert collisions between existing objects, call
Traits add multiple checks to prevent collisions between existing objects, call
init() method, carry over $app and set $owner properties and calculate 'name'
by combining it with the parent.

Expand Down
10 changes: 5 additions & 5 deletions src/DebugTrait.php
Expand Up @@ -12,7 +12,7 @@ trait DebugTrait
public $debug = false;

/** @var array<string, array<int, string>> Helps debugTraceChange. */
protected array $_prevTrace = [];
protected array $_previousTrace = [];

/**
* Outputs message to STDERR.
Expand Down Expand Up @@ -90,14 +90,14 @@ public function debugTraceChange(string $trace = 'default'): void
}
}

if (isset($this->_prevTrace[$trace]) && array_diff($this->_prevTrace[$trace], $bt)) {
$d1 = array_diff($this->_prevTrace[$trace], $bt);
$d2 = array_diff($bt, $this->_prevTrace[$trace]);
if (isset($this->_previousTrace[$trace]) && array_diff($this->_previousTrace[$trace], $bt)) {
$d1 = array_diff($this->_previousTrace[$trace], $bt);
$d2 = array_diff($bt, $this->_previousTrace[$trace]);

$this->log('debug', 'Call path for ' . $trace . ' has diverged (was ' . implode(', ', $d1) . ', now ' . implode(', ', $d2) . ")\n");
}

$this->_prevTrace[$trace] = $bt;
$this->_previousTrace[$trace] = $bt;
}

/**
Expand Down
11 changes: 1 addition & 10 deletions src/Exception.php
Expand Up @@ -105,8 +105,6 @@ public function getParams(): array
}

/**
* Augment existing exception with more info.
*
* @param mixed $value
*
* @return $this
Expand All @@ -119,8 +117,6 @@ public function addMoreInfo(string $param, $value): self
}

/**
* Add a suggested/possible solution to the exception.
*
* @return $this
*/
public function addSolution(string $solution): self
Expand All @@ -131,25 +127,20 @@ public function addSolution(string $solution): self
}

/**
* Get the solutions array.
*
* @return array<int, string>
*/
public function getSolutions(): array
{
return $this->solutions;
}

/**
* Get the custom exception title.
*/
public function getCustomExceptionTitle(): string
{
return $this->customExceptionTitle;
}

/**
* Set Custom Translator adapter.
* Set custom Translator adapter.
*
* @return $this
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Translator/Translator.php
Expand Up @@ -19,10 +19,8 @@ class Translator

private ?ITranslatorAdapter $adapter = null;

/** Default domain of translations */
protected string $defaultDomain = 'atk';

/** Default language of translations */
protected string $defaultLocale = 'en';

private function __construct()
Expand Down
3 changes: 0 additions & 3 deletions tests/DynamicMethodTraitTest.php
Expand Up @@ -130,9 +130,6 @@ public function testDoubleMethodException(): void
$m->addMethod('sum', $this->createSumFx());
}

/**
* Test removing dynamic method.
*/
public function testRemoveMethod(): void
{
// simple method
Expand Down
8 changes: 4 additions & 4 deletions tests/ExceptionTest.php
Expand Up @@ -20,7 +20,7 @@ public function testBasic(): void

self::assertSame(['a1' => 111, 'a2' => 222], $m->getParams());

$m = new Exception('PrevError');
$m = new Exception('PreviousError');
$m = new Exception('TestIt', 123, $m);
$m->addMoreInfo('a1', 222);
$m->addMoreInfo('a2', 333);
Expand All @@ -30,19 +30,19 @@ public function testBasic(): void
// get HTML
$ret = $m->getHtml();
self::assertMatchesRegularExpression('~TestIt~', $ret);
self::assertMatchesRegularExpression('~PrevError~', $ret);
self::assertMatchesRegularExpression('~PreviousError~', $ret);
self::assertMatchesRegularExpression('~333~', $ret);

// get colorful text
$ret = $m->getColorfulText();
self::assertMatchesRegularExpression('~TestIt~', $ret);
self::assertMatchesRegularExpression('~PrevError~', $ret);
self::assertMatchesRegularExpression('~PreviousError~', $ret);
self::assertMatchesRegularExpression('~333~', $ret);

// get JSON
$ret = $m->getJson();
self::assertMatchesRegularExpression('~TestIt~', $ret);
self::assertMatchesRegularExpression('~PrevError~', $ret);
self::assertMatchesRegularExpression('~PreviousError~', $ret);
self::assertMatchesRegularExpression('~333~', $ret);

// to safe string
Expand Down
12 changes: 2 additions & 10 deletions tests/FactoryTest.php
Expand Up @@ -220,13 +220,11 @@ public function testInjection(): void

public function testArguments(): void
{
/*
$s1 = Factory::factory([FactoryTestMock::class, 'hello']);
self::{'assertEquals'}(['hello'], $s1->args);
self::assertSame(['hello'], $s1->args);

$s1 = Factory::factory([FactoryTestMock::class, 'hello', 'world']);
self::{'assertEquals'}(['hello', 'world'], $s1->args);
*/
self::assertSame(['hello', 'world'], $s1->args);

$s1 = Factory::factory([FactoryTestMock::class, null, 'world']);
self::assertSame([null, 'world'], $s1->args);
Expand Down Expand Up @@ -355,9 +353,6 @@ public function testNonDiInject(): void
Factory::factory([FactoryTestMock::class], ['foo' => 'hello']);
}

/**
* Test seed property merging.
*/
public function testPropertyMerging(): void
{
$s1 = Factory::factory(
Expand Down Expand Up @@ -401,9 +396,6 @@ public function testFactoryException1(): void
Factory::factory(['wrong_parameter' => 'qwerty']);
}

/**
* Test factory parameters.
*/
public function testFactoryParameters(): void
{
$m = new FactoryFactoryDiMock();
Expand Down

0 comments on commit 839f39f

Please sign in to comment.