Passed
Push — develop ( f63f67...7af1af )
by Jens
04:23
created

renderDocument()   C

Complexity

Conditions 9
Paths 64

Size

Total Lines 83
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 9
eloc 58
c 3
b 0
f 1
nc 64
nop 4
dl 0
loc 83
rs 5.48

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * @param \CloudControl\Cms\storage\entities\Document $document
4
 * @param string $path
5
 * @param \CloudControl\Cms\cc\Request $request
6
 * @param string $cmsPrefix
7
 */
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">&nbsp;</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);">
92
            <i class="fa fa-list-alt"></i>
93
            Details
94
          </a>
95
        </li>
96
      </ul>
97
    </div>
98
  </td>
99
<?php } ?>
100