Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali214 committed Nov 26, 2024
1 parent faca4b6 commit d543cde
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
37 changes: 25 additions & 12 deletions src/JsonMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,15 @@ public function map($json, $object, $strict = false)
}

/**
* @param ReflectionMethod|null $method
* @param object $object
* @param int|string $key
* @param mixed $value
* Add additional properties by invoking the specified method.
*
* @param ReflectionMethod|null $method Method to be called to add
* additional properties to the class.
* @param object $object Class instance on which the method
* is invoked.
* @param int|string $key The name of additional property.
* @param mixed $value The value of additional property.
*
* @return void
*/
protected function addAdditionalProperty($method, $object, $key, $value)
Expand All @@ -339,8 +344,9 @@ protected function addAdditionalProperty($method, $object, $key, $value)
$value = $this->getMappedValue(
$value,
$this->getDocTypeForArrayOrMixed(
$this->getParameterType($method->getParameters()[0]),
$annotations
$this->getParameterType($method->getParameters()[1]),
$annotations,
1
),
$this->getMapByAnnotationFromParsed($annotations),
$this->getFactoryMethods($annotations),
Expand Down Expand Up @@ -1654,24 +1660,31 @@ protected function reflectionTypeToString($type)
}

/**
* @param string|null $type
* @param array $annotations
* If the actual type is array or mixed, use the annotations to extract
* the type.
*
* @param string|null $type The actual type of the parameter.
* @param array $annotations The annotations to search the type.
* @param int $index The position of parameter in the function.
*
* @return string|null
*/
public function getDocTypeForArrayOrMixed($type, $annotations)
public function getDocTypeForArrayOrMixed($type, $annotations, $index = 0)
{
if (($type === null || $type === 'array' || $type === 'array|null')
&& isset($annotations['param'][0])
&& isset($annotations['param'][$index])
) {
list($type) = explode(' ', trim($annotations['param'][0]));
list($type) = explode(' ', trim($annotations['param'][$index]));
}

return $type;
}

/**
* @param array $annotations
* Get all factory methods from the list of annotations.
*
* @param array $annotations The annotations list.
*
* @return string[]
*/
public function getFactoryMethods(array $annotations)
Expand Down
2 changes: 1 addition & 1 deletion tests/JsonMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ public function testAdditionalPropertiesTyped()
new JsonMapperTest_Simple()
);
$this->assertEquals(1, count($fm->additional));
$this->assertEquals("hello", $fm->additional['random11']);
$this->assertEquals(123123, $fm->additional['random22']);
}

public function testAdditionalPropertiesFactory()
Expand Down
2 changes: 1 addition & 1 deletion tests/JsonMapperTest/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function addAdditionalProperty($key, $value)

/**
* @param string $key
* @param string $value
* @param int $value
*/
public function addTypedAdditionalProperty($key, $value)
{
Expand Down

0 comments on commit d543cde

Please sign in to comment.