Passed
Push — master ( 3f6c85...9c6499 )
by Jens
02:40
created

function.renderDocument.php ➔ renderDocument()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 46
Code Lines 38

Duplication

Lines 15
Ratio 32.61 %

Importance

Changes 0
Metric Value
cc 7
eloc 38
nc 16
nop 3
dl 15
loc 46
rs 6.7272
c 0
b 0
f 0
1
<?
2
/**
3
 * @param \library\storage\Document $document
4
 * @param string                    $cmsPrefix
5
 * @param string                    $slugPrefix
6
 */
7
function renderDocument($document, $cmsPrefix, $slugPrefix = '') {?>
8
	<div class="grid-box-10">
9
		<h3>
10
			<a class="btn documentTitle" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix . $document->slug?>" title="Edit">
11
				<i class="fa fa-file-text-o"></i>
12
				<small class="state <?=strtolower($document->state)?>"><i class="fa <?=$document->state == 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i></small>
13
				<?=$document->title?>
14
			</a>
15
			<? if ($document->unpublishedChanges) : ?><small class="small unpublished-changes">Unpublished Changes</small><? endif ?>
0 ignored issues
show
Documentation introduced by
The property unpublishedChanges does not exist on object<library\storage\Document>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
16
			<small class="small documentType"><?=$document->documentType?></small>
17
			<small class="small lastModified" title="<?=date('r', $document->lastModificationDate)?>">
18
				<span class="label">Modified:</span>
19
				<?=\library\cc\StringUtil::timeElapsedString($document->lastModificationDate)?>
20
			</small>
21
			<small class="small lastModifiedBy">
22
				<span class="label">By:</span>
23
				<?=$document->lastModifiedBy?>
24
			</small>
25
		</h3>
26
	</div>
27
	<div class="documentActions grid-box-2">
28 View Code Duplication
		<? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Documentation introduced by
The property unpublishedChanges does not exist on object<library\storage\Document>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
29
            <?renderAction('Publish',
30
                'publish',
31
                \library\cc\Request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug,
32
                'check');?>
33
		<? endif ?>
34
		<? if ($document->state == 'published') : ?>
35
			<?renderAction('Unpublish',
36
				'unpublish',
37
				\library\cc\Request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug,
38
				'times');?>
39
		<? endif ?>
40
		<?renderAction('Edit',
41
			'',
42
			\library\cc\Request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug,
43
			'pencil');?>
44 View Code Duplication
		<? if ($document->state == 'unpublished') : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
			<?renderAction('Delete',
46
				'error',
47
				\library\cc\Request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug,
48
				'trash',
49
                'return confirm(\'Are you sure you want to delete this document?\');');?>
1 ignored issue
show
Documentation introduced by
'return confirm(\'Are yo...ete this document?\');' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
		<? endif ?>
51
	</div>
52
<?}?>
53