Conditions | 9 |
Paths | 64 |
Total Lines | 83 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
8 | function renderDocument($document, $path, $request, $cmsPrefix) |
||
9 | { ?> |
||
10 | <?php |
||
11 | $documentSlug = substr($path, 1) . ($path === '/' ? '' : '/') . $document->slug; |
||
12 | $editDocumentLink = $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $documentSlug; |
||
13 | $deleteDocumentLink = $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $documentSlug; |
||
14 | ?> |
||
15 | <td class="icon" title="<?= $document->type ?>"> |
||
16 | <i class="fa fa-file-text-o"></i> |
||
17 | </td> |
||
18 | <td class="icon" title="<?= $document->state ?>"> |
||
19 | <i class="fa <?= $document->state === 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i> |
||
20 | </td> |
||
21 | <td> |
||
22 | <a href="<?= $editDocumentLink ?>"><?= $document->title ?></a> |
||
23 | <?php if ($document->unpublishedChanges) : ?> |
||
24 | <small class="small unpublished-changes">Unpublished Changes</small> |
||
25 | <?php endif ?> |
||
26 | <small class="small document-type"><?= $document->documentType ?></small> |
||
27 | <div class="details"> |
||
28 | <table> |
||
29 | <tr> |
||
30 | <th>Document Type</th> |
||
31 | <td><?= $document->documentType ?></td> |
||
32 | <th>Last Modified By</th> |
||
33 | <td><?= $document->lastModifiedBy ?></td> |
||
34 | </tr> |
||
35 | <tr> |
||
36 | <th>Created</th> |
||
37 | <td title="<?= date('d-m-Y H:i:s', |
||
38 | $document->creationDate) ?>"><?= \CloudControl\Cms\util\StringUtil::timeElapsedString($document->creationDate) ?></td> |
||
39 | <th>Last Modified</th> |
||
40 | <td title="<?= date('d-m-Y H:i:s', |
||
41 | $document->lastModificationDate) ?>"><?= \CloudControl\Cms\util\StringUtil::timeElapsedString($document->lastModificationDate) ?></td> |
||
42 | </tr> |
||
43 | <tr> |
||
44 | <td colspan="2"> </td> |
||
45 | <th>Published</th> |
||
46 | <?php if ($document->state === 'published') : ?> |
||
47 | <td title="<?= date('d-m-Y H:i:s', |
||
48 | $document->publicationDate) ?>"><?= \CloudControl\Cms\util\StringUtil::timeElapsedString($document->publicationDate) ?></td> |
||
49 | <?php else : ?> |
||
50 | <td>Not yet</td> |
||
51 | <?php endif ?> |
||
52 | </tr> |
||
53 | </table> |
||
54 | </div> |
||
55 | </td> |
||
56 | <td class="icon context-menu-container"> |
||
57 | <div class="context-menu"> |
||
58 | <i class="fa fa-ellipsis-v"></i> |
||
59 | <ul> |
||
60 | <li> |
||
61 | <a href="<?= $editDocumentLink ?>"> |
||
62 | <i class="fa fa-pencil"></i> |
||
63 | Edit |
||
64 | </a> |
||
65 | </li> |
||
66 | <?php if ($document->state === 'unpublished' || $document->unpublishedChanges) : ?> |
||
67 | <li> |
||
68 | <a href="<?= $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $documentSlug ?>"> |
||
69 | <i class="fa fa-check"></i> |
||
70 | Publish |
||
71 | </a> |
||
72 | </li> |
||
73 | <?php endif ?> |
||
74 | <?php if ($document->state === 'published') : ?> |
||
75 | <li> |
||
76 | <a href="<?= $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $documentSlug ?>"> |
||
77 | <i class="fa fa-times"></i> |
||
78 | Unpublish |
||
79 | </a> |
||
80 | </li> |
||
81 | <?php endif ?> |
||
82 | <?php if ($document->state === 'unpublished') : ?> |
||
83 | <li> |
||
84 | <a href="<?= $deleteDocumentLink ?>" onclick="return confirm('Are you sure you want to delete this document?');"> |
||
85 | <i class="fa fa-trash"></i> |
||
86 | Delete |
||
87 | </a> |
||
88 | </li> |
||
89 | <?php endif ?> |
||
90 | <li> |
||
91 | <a href="#" onclick="return showDocumentDetails(this);"> |
||
100 |