Conditions | 1 |
Paths | 1 |
Total Lines | 83 |
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 |
||
44 | public function setupPermissionsAndRoles() |
||
45 | { |
||
46 | $auth = Yii::$app->authManager; |
||
47 | |||
48 | /* |
||
49 | * Permissions |
||
50 | */ |
||
51 | |||
52 | // Admin |
||
53 | $administration = $auth->createPermission('admin'); |
||
54 | $administration->description = 'Administrate everyting'; |
||
55 | $auth->add($administration); |
||
56 | |||
57 | // Devices |
||
58 | $setDevices = $auth->createPermission('setDevices'); |
||
59 | $setDevices->description = 'Manage devices'; |
||
60 | $auth->add($setDevices); |
||
61 | |||
62 | // Screens |
||
63 | $setScreens = $auth->createPermission('setScreens'); |
||
64 | $setScreens->description = 'Manage screens'; |
||
65 | $auth->add($setScreens); |
||
66 | |||
67 | $previewScreen = $auth->createPermission('previewScreen'); |
||
68 | $previewScreen->description = 'Preview screens'; |
||
69 | $auth->add($previewScreen); |
||
70 | |||
71 | // Templates |
||
72 | $setTemplates = $auth->createPermission('setTemplates'); |
||
73 | $setTemplates->description = 'Manage screen templates'; |
||
74 | $auth->add($setTemplates); |
||
75 | |||
76 | // Flows |
||
77 | $setFlows = $auth->createPermission('setFlows'); |
||
78 | $setFlows->description = 'Manage flows'; |
||
79 | $auth->add($setFlows); |
||
80 | |||
81 | // Flow content |
||
82 | $setFlowContent = $auth->createPermission('setFlowContent'); |
||
83 | $setFlowContent->description = 'Manage flow content'; |
||
84 | $auth->add($setFlowContent); |
||
85 | |||
86 | // Own flow content |
||
87 | $setOwnFlowContent = $auth->createPermission('setOwnFlowContent'); |
||
88 | $setOwnFlowContent->description = 'Manage owned flow content'; |
||
89 | $auth->add($setOwnFlowContent); |
||
90 | |||
91 | // Content |
||
92 | $setContent = $auth->createPermission('setContent'); |
||
93 | $setContent->description = 'Manage all content'; |
||
94 | $auth->add($setContent); |
||
95 | |||
96 | // Upload |
||
97 | $upload = $auth->createPermission('upload'); |
||
98 | $upload->description = 'Upload content'; |
||
99 | $auth->add($upload); |
||
100 | |||
101 | /* |
||
102 | * Roles |
||
103 | */ |
||
104 | |||
105 | $contentCreator = $auth->createRole('Content creator'); |
||
106 | $contentCreator->data = ['requireFlow' => true]; |
||
107 | $auth->add($contentCreator); |
||
108 | $auth->addChild($contentCreator, $upload); |
||
109 | $auth->addChild($contentCreator, $setOwnFlowContent); |
||
110 | |||
111 | $screenManager = $auth->createRole('Screen manager'); |
||
112 | $auth->add($screenManager); |
||
113 | $auth->addChild($screenManager, $setFlowContent); |
||
114 | $auth->addChild($screenManager, $setFlows); |
||
115 | $auth->addChild($screenManager, $setTemplates); |
||
116 | $auth->addChild($screenManager, $setScreens); |
||
117 | $auth->addChild($screenManager, $previewScreen); |
||
118 | $auth->addChild($screenManager, $contentCreator); |
||
119 | |||
120 | $admin = $auth->createRole('Administrator'); |
||
121 | $auth->add($admin); |
||
122 | $auth->addChild($admin, $administration); |
||
123 | $auth->addChild($admin, $setDevices); |
||
124 | $auth->addChild($admin, $setContent); |
||
125 | $auth->addChild($admin, $screenManager); |
||
126 | } |
||
127 | } |
||
128 |