Conditions | 12 |
Paths | 11 |
Total Lines | 51 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | public function addUserPermissionsToCategoryTreeData(ModifyTreeDataEvent $event): void |
||
61 | { |
||
62 | // Only evaluate this in the backend |
||
63 | if (!($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface |
||
64 | || ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() |
||
65 | ) { |
||
66 | return; |
||
67 | } |
||
68 | |||
69 | $dataProvider = $event->getProvider(); |
||
70 | $treeData = $event->getTreeData(); |
||
71 | |||
72 | if (!$this->backendUserAuthentication->isAdmin() && $dataProvider->getTableName() === $this->categoryTableName) { |
||
|
|||
73 | |||
74 | // Get User permissions related to category |
||
75 | $categoryMountPoints = $this->backendUserAuthentication->getCategoryMountPoints(); |
||
76 | |||
77 | // Backup child nodes to be processed. |
||
78 | $treeNodeCollection = $treeData->getChildNodes(); |
||
79 | |||
80 | if (!empty($categoryMountPoints) && !empty($treeNodeCollection)) { |
||
81 | |||
82 | // Check the rootline against categoryMountPoints when tree was filtered |
||
83 | if ($dataProvider->getRootUid() !== null) { |
||
84 | if (in_array($dataProvider->getRootUid(), $categoryMountPoints)) { |
||
85 | return; |
||
86 | } |
||
87 | $uidsInRootline = $this->findUidsInRootline($dataProvider->getRootUid()); |
||
88 | if (!empty(array_intersect($categoryMountPoints, $uidsInRootline))) { |
||
89 | // One of the parents was found in categoryMountPoints so all children are secure |
||
90 | return; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | // First, remove all child nodes which must be analyzed to be considered as "secure". |
||
95 | // The nodes were backed up in variable $treeNodeCollection beforehand. |
||
96 | $treeData->removeChildNodes(); |
||
97 | |||
98 | // Create an empty tree node collection to receive the secured nodes. |
||
99 | /** @var TreeNodeCollection $securedTreeNodeCollection */ |
||
100 | $securedTreeNodeCollection = GeneralUtility::makeInstance(TreeNodeCollection::class); |
||
101 | |||
102 | foreach ($categoryMountPoints as $categoryMountPoint) { |
||
103 | $treeNode = $this->lookUpCategoryMountPointInTreeNodes((int)$categoryMountPoint, $treeNodeCollection); |
||
104 | if ($treeNode !== null) { |
||
105 | $securedTreeNodeCollection->append($treeNode); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | // Reset child nodes. |
||
110 | $treeData->setChildNodes($securedTreeNodeCollection); |
||
111 | } |
||
175 |