Completed
Push — dev5 ( cf4e4a...8e8b96 )
by Ron
08:41
created

FileLinks::toArray()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
nc 8
nop 1
dl 0
loc 15
rs 9.8666
c 1
b 0
f 0
1
<?php
2
3
namespace App\Http\Resources;
4
5
use App\Customers;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, App\Http\Resources\Customers. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Carbon\Carbon;
7
use Illuminate\Http\Resources\Json\JsonResource;
8
9
class FileLinks extends JsonResource
10
{
11
    /**
12
     * Transform the resource into an array.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @return array
16
     */
17
    public function toArray($request)
18
    {
19
        // return parent::toArray($request);
20
        return [
21
            'link_id'      => $this->link_id,
1 ignored issue
show
Bug Best Practice introduced by
The property link_id does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
            'user_id'      => $this->user_id,
1 ignored issue
show
Bug Best Practice introduced by
The property user_id does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
            'cust_id'      => $this->cust_id,
1 ignored issue
show
Bug Best Practice introduced by
The property cust_id does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
24
            'cust_name'    => $this->cust_id ? Customers::find($this->cust_id)->name : 'None',
25
            'link_hash'    => $this->link_hash,
1 ignored issue
show
Bug Best Practice introduced by
The property link_hash does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
26
            'link_name'    => $this->link_name,
1 ignored issue
show
Bug Best Practice introduced by
The property link_name does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
27
            'exp_format'   => Carbon::parse($this->expire)->format('M d, Y'),
1 ignored issue
show
Bug Best Practice introduced by
The property expire does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
28
            'expired'      => $this->expire < Carbon::now() ? 1 : 0,
29
            'exp_stamp'    => Carbon::parse($this->expire)->format('Y-m-d'),
30
            'allow_upload' => $this->allow_upload,
1 ignored issue
show
Bug Best Practice introduced by
The property allow_upload does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
            'file_count'   => isset($this->file_link_files_count) ? $this->file_link_files_count : 0
1 ignored issue
show
Bug Best Practice introduced by
The property file_link_files_count does not exist on App\Http\Resources\FileLinks. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
        ];
33
    }
34
}
35