TreeItemFolder::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
/*
5
 * This file is part of the package typo3/cms-digital-asset-management.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10
11
namespace TYPO3\CMS\DigitalAssetManagement\Entity;
12
13
use TYPO3\CMS\Core\Resource\Folder;
14
15
/**
16
 * Immutable folder object, used by getFolderItemsAction().
17
 *
18
 * @see FolderItemFile
19
 * @see FolderItemImage
20
 */
21
class TreeItemFolder implements \JsonSerializable
22
{
23
    /**
24
     * @var string Folder name, not full path, eg. "myFolder"
25
     */
26
    protected $name;
27
28
    /**
29
     * @var string Always set to "folder"
30
     */
31
    protected $type = 'folder';
32
33
    /**
34
     * @var int FAL identifier, eg. "42:/path/to/folder"
35
     */
36
    protected $identifier;
37
38
    /**
39
     * Save state of folder is not part of MVP
40
     *
41
     * @var bool Folder is expanded, so children are visible, default: false
42
     */
43
    protected $expanded;
44
45
    /**
46
     * @var bool Folder has children
47
     */
48
    protected $hasChildren;
49
50
    /**
51
     * @var string Public path to Icon file, currently always points to apps-filetree-folder-default.svg
52
     */
53
    protected $icon = '/typo3/sysext/core/Resources/Public/Icons/T3Icons/apps/apps-filetree-folder-default.svg';
54
55
    /**
56
     * @param Folder $folder
57
     */
58
    public function __construct(Folder $folder)
59
    {
60
        $this->name = $folder->getName();
61
        $this->identifier = $folder->getCombinedIdentifier();
0 ignored issues
show
Documentation Bug introduced by
The property $identifier was declared of type integer, but $folder->getCombinedIdentifier() is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
62
        $this->expanded = false;
63
        $this->hasChildren = count($folder->getSubfolders()) > 0;
64
    }
65
66
    public function jsonSerialize()
67
    {
68
        return [
69
            'name' => $this->name,
70
            'type' => $this->type,
71
            'identifier' => $this->identifier,
72
            'expanded' => $this->expanded,
73
            'hasChildren' => $this->hasChildren,
74
            'icon' => $this->icon
75
        ];
76
    }
77
}
78