@@ -44,21 +44,26 @@ public function __construct(Hydrator $hydrator)
44
44
*/
45
45
public function forge (Category $ category ): void
46
46
{
47
- $ pathElements = explode ('/ ' , $ category ->getPath ());
47
+ $ pathElements = array_map (
48
+ function ($ element ) {
49
+ return (int )$ element ;
50
+ },
51
+ explode ('/ ' , $ category ->getPath ())
52
+ );
48
53
$ parentId = null ;
49
- foreach ($ pathElements as $ pathElement ) {
54
+ foreach ($ pathElements as $ id ) {
50
55
if ($ parentId && $ this ->hasNodeById ($ parentId )) {
51
- if (!$ this ->hasNodeById (( int ) $ pathElement )) {
52
- $ this ->indexById [( int ) $ pathElement ] = new Node (( int ) $ pathElement , $ this );
53
- $ this ->getNodeById ($ parentId )->addChild ($ this ->indexById [( int ) $ pathElement ]);
54
- if ($ category ->getId () == $ pathElement ) {
55
- $ this ->indexById [( int ) $ pathElement ]->setModel ($ category );
56
+ if (!$ this ->hasNodeById ($ id )) {
57
+ $ this ->indexById [$ id ] = new Node ($ id , $ this );
58
+ $ this ->getNodeById ($ parentId )->addChild ($ this ->indexById [$ id ]);
59
+ if ($ category ->getId () == $ id ) {
60
+ $ this ->indexById [$ id ]->setModel ($ category );
56
61
}
57
62
}
58
- } elseif (!$ this ->hasNodeById (( int ) $ pathElement )) {
59
- $ this ->indexById [( int ) $ pathElement ] = new Node (( int ) $ pathElement , $ this );
63
+ } elseif (!$ this ->hasNodeById ($ id )) {
64
+ $ this ->indexById [$ id ] = new Node ($ id , $ this );
60
65
}
61
- $ parentId = ( int ) $ pathElement ;
66
+ $ parentId = $ id ;
62
67
}
63
68
}
64
69
0 commit comments