DatastoreAttribute::getEditButtonAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Phpsa\Datastore\Models\Traits\Attribute;
4
use Phpsa\Datastore\Datastore as DatastoreFactory;
5
use Phpsa\Datastore\Helpers;
6
7
/**
8
 * Trait UserAttribute.
9
 */
10
trait DatastoreAttribute
11
{
12
13
	/**
14
     * @return string
15
     */
16
    public function getEditButtonAttribute()
17
    {
18
        return '<a href="'.route('admin.ams.content.update', ['asset' => $this->content_path, 'id' => $this->id]).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.general.crud.edit').'" class="btn btn-primary"><i class="fas fa-edit"></i></a>';
19
	}
20
21
	  /**
22
     * @return string
23
     */
24
    public function getDeleteButtonAttribute()
25
    {
26
27
            return '<a href="'.route('admin.ams.content.destroy', $this).'"
28
			data-method="delete"
29
			data-trans-button-cancel="'.__('buttons.general.cancel').'"
30
			data-trans-button-confirm="'.__('buttons.general.crud.delete').'"
31
			data-trans-title="'.__('strings.backend.general.are_you_sure').'"
32
			class="btn btn-danger"><i class="fas fa-trash" data-toggle="tooltip" data-placement="top" title="'.__('buttons.general.crud.delete').'"></i></a> ';
33
34
    }
35
36
	    /**
37
     * @return string
38
     */
39
    public function getActionButtonsAttribute()
40
    {
41
42
		if($this->id)
43
		{
44
        	return '<div class="btn-group" role="group" aria-label="'.__('labels.backend.access.users.user_actions').'">
45
			'.$this->edit_button.'
46
			'.$this->delete_button.'
47
			</div>';
48
		}
49
	}
50
51
	public function getContentPathAttribute(){
52
		return Helpers::getPath($this->type);
0 ignored issues
show
Bug introduced by
Are you sure the usage of Phpsa\Datastore\Helpers::getPath($this->type) targeting Phpsa\Datastore\Helpers::getPath() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
	}
54
55
56
/*	public function getParentsAttribute(){
57
		$rows = self::find(1);
58
		$data['parents'] = $this->db->query('select distinct(type), name, accept_limit from datastore where accept LIKE ?', array('%' . $newasset->type . '%'))->result_array();
59
60
	}*/
61
62
	public function getDatastoreAttribute(){
63
		if($this->id){
64
			return DatastoreFactory::getAsset($this->type, $this->id);
65
		}
66
		if($this->type){
67
			return DatastoreFactory::dispence($this->type);
0 ignored issues
show
Bug introduced by
The method dispence() does not exist on Phpsa\Datastore\Datastore. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
			return DatastoreFactory::/** @scrutinizer ignore-call */ dispence($this->type);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
		}
69
	}
70
71
	public function getRouteAttribute(){
72
		return $this->type ? Helpers::callStatic($this->type, 'route', [$this]) : null;
73
	}
74
75
	public function routeChild($parentSlug){
76
		return $this->type ? Helpers::callStatic($this->type, 'route', [$this, $parentSlug]) : null;
77
78
	}
79
80
}