Completed
Push — develop ( de01c4...6d2038 )
by Abdelrahman
10:19
created

MediaDataTable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 56
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A query() 0 6 1
A getColumns() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\DataTables;
6
7
use Spatie\MediaLibrary\Models\Media;
8
use Cortex\Foundation\Transformers\MediaTransformer;
9
10
class MediaDataTable extends AbstractDataTable
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $model = Media::class;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $createButton = false;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected $builderParameters = [
26
        'initComplete' => 'function (settings) {
27
            implicitForms.initialize();
28
        }',
29
    ];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected $transformer = MediaTransformer::class;
35
36
    /**
37
     * Get the query object to be processed by dataTables.
38
     *
39
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Database\Que...tabase\Eloquent\Builder.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
40
     */
41
    public function query()
42
    {
43
        $query = $this->resource->media()->orderBy('order_column', 'ASC');
0 ignored issues
show
Documentation introduced by
The property resource does not exist on object<Cortex\Foundation...aTables\MediaDataTable>. 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...
44
45
        return $this->applyScopes($query);
46
    }
47
48
    /**
49
     * Get columns.
50
     *
51
     * @return array
52
     */
53
    protected function getColumns(): array
54
    {
55
        return [
56
            'name' => ['title' => trans('cortex/foundation::common.name'), 'responsivePriority' => 0],
57
            'file_name' => ['title' => trans('cortex/foundation::common.file_name')],
58
            'mime_type' => ['title' => trans('cortex/foundation::common.mime_type')],
59
            'size' => ['title' => trans('cortex/foundation::common.size')],
60
            'created_at' => ['title' => trans('cortex/foundation::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
61
            'updated_at' => ['title' => trans('cortex/foundation::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
62
            'delete' => ['title' => trans('cortex/foundation::common.delete'), 'orderable' => false, 'searchable' => false, 'render' => '"<a href=\"#\" data-toggle=\"modal\" data-target=\"#delete-confirmation\" data-modal-action=\""+data+"\" data-modal-title=\"'.trans('cortex/foundation::messages.delete_confirmation_title').'\" data-modal-body=\"" + Lang.trans(\'cortex/foundation::messages.delete_confirmation_body\', {type: \'media\', name: full.name}) + "\" title=\"'.trans('cortex/foundation::common.delete').'\"><i class=\"fa fa-trash text-danger\"></i></a>"'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 568 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
63
        ];
64
    }
65
}
66