mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Fix "Found a redundant condition when evaluating docblock-defined type $composerJsonPath and trying to reconcile type 'string' to string" bug pointed by Psalm
This commit is contained in:
@@ -30,14 +30,9 @@ class Composer
|
|||||||
* @param string $nodeName Name of node who value should be returned
|
* @param string $nodeName Name of node who value should be returned
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public static function getValue($composerJsonPath, $nodeName)
|
public static function getValue(string $composerJsonPath, string $nodeName): ?string
|
||||||
{
|
{
|
||||||
$composerJsonString = is_string($composerJsonPath);
|
$composerJsonReadable = is_readable($composerJsonPath);
|
||||||
$composerJsonReadable = false;
|
|
||||||
|
|
||||||
if ($composerJsonString) {
|
|
||||||
$composerJsonReadable = is_readable($composerJsonPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Provided path or name of node are invalid?
|
* Provided path or name of node are invalid?
|
||||||
@@ -46,12 +41,12 @@ class Composer
|
|||||||
*
|
*
|
||||||
* Nothing to do
|
* Nothing to do
|
||||||
*/
|
*/
|
||||||
if (!$composerJsonString || !is_string($nodeName) || !$composerJsonReadable || empty($nodeName)) {
|
if (!$composerJsonReadable || empty($nodeName)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = file_get_contents($composerJsonPath);
|
$content = file_get_contents($composerJsonPath);
|
||||||
$data = json_decode($content);
|
$data = json_decode($content, false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unknown data from the composer.json file or there is no node with given name?
|
* Unknown data from the composer.json file or there is no node with given name?
|
||||||
|
|||||||
@@ -35,23 +35,15 @@ class ComposerTest extends BaseTestCase
|
|||||||
static::assertHasNoConstructor(Composer::class);
|
static::assertHasNoConstructor(Composer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testGetValueNotExistingComposerJson(): void
|
||||||
* @param string $composerJsonPath Empty value, e.g. ""
|
|
||||||
* @dataProvider provideEmptyValue
|
|
||||||
*/
|
|
||||||
public function testGetValueNotExistingComposerJson($composerJsonPath)
|
|
||||||
{
|
{
|
||||||
self::assertNull(Composer::getValue($composerJsonPath, ''));
|
self::assertNull(Composer::getValue('', ''));
|
||||||
self::assertNull(Composer::getValue('not/existing/composer.json', ''));
|
self::assertNull(Composer::getValue('not/existing/composer.json', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testGetValueNotExistingNode(): void
|
||||||
* @param string $nodeName Empty value, e.g. ""
|
|
||||||
* @dataProvider provideEmptyValue
|
|
||||||
*/
|
|
||||||
public function testGetValueNotExistingNode($nodeName)
|
|
||||||
{
|
{
|
||||||
self::assertNull(Composer::getValue($this->composerJsonPath, $nodeName));
|
self::assertNull(Composer::getValue($this->composerJsonPath, ''));
|
||||||
self::assertNull(Composer::getValue($this->composerJsonPath, 'not_existing_node'));
|
self::assertNull(Composer::getValue($this->composerJsonPath, 'not_existing_node'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +53,7 @@ class ComposerTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider getExistingNode
|
* @dataProvider getExistingNode
|
||||||
*/
|
*/
|
||||||
public function testGetValueExistingNode($nodeName, $nodeValue)
|
public function testGetValueExistingNode(string $nodeName, string $nodeValue): void
|
||||||
{
|
{
|
||||||
self::assertEquals($nodeValue, Composer::getValue($this->composerJsonPath, $nodeName));
|
self::assertEquals($nodeValue, Composer::getValue($this->composerJsonPath, $nodeName));
|
||||||
}
|
}
|
||||||
@@ -71,7 +63,7 @@ class ComposerTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @return Generator
|
* @return Generator
|
||||||
*/
|
*/
|
||||||
public function getExistingNode()
|
public function getExistingNode(): Generator
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
'name',
|
'name',
|
||||||
|
|||||||
Reference in New Issue
Block a user