1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of DivineNii opensource projects. |
7
|
|
|
* |
8
|
|
|
* PHP version 7.4 and above required |
9
|
|
|
* |
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
11
|
|
|
* @copyright 2019 DivineNii (https://divinenii.com/) |
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Rade\Database\Doctrine\Form\DataTransformer; |
19
|
|
|
|
20
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
|
|
|
21
|
|
|
use Doctrine\Common\Collections\Collection; |
|
|
|
|
22
|
|
|
use Symfony\Component\Form\DataTransformerInterface; |
23
|
|
|
use Symfony\Component\Form\Exception\TransformationFailedException; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Bernhard Schussek <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class CollectionToArrayTransformer implements DataTransformerInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Transforms a collection into an array. |
32
|
|
|
* |
33
|
|
|
* @throws TransformationFailedException |
34
|
|
|
*/ |
35
|
|
|
public function transform(mixed $collection): mixed |
36
|
|
|
{ |
37
|
|
|
if (null === $collection) { |
38
|
|
|
return []; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// For cases when the collection getter returns $collection->toArray() |
42
|
|
|
// in order to prevent modifications of the returned collection |
43
|
|
|
if (\is_array($collection)) { |
44
|
|
|
return $collection; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (!$collection instanceof Collection) { |
48
|
|
|
throw new TransformationFailedException('Expected a Doctrine\Common\Collections\Collection object.'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $collection->toArray(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Transforms choice keys into entities. |
56
|
|
|
* |
57
|
|
|
* @param mixed $array An array of entities |
58
|
|
|
*/ |
59
|
|
|
public function reverseTransform(mixed $array): Collection |
60
|
|
|
{ |
61
|
|
|
if ('' === $array || null === $array) { |
62
|
|
|
$array = []; |
63
|
|
|
} else { |
64
|
|
|
$array = (array) $array; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return new ArrayCollection($array); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths