BaseTransformer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B transform() 0 29 6
transformData() 0 1 ?
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: xuan
5
 * Date: 12/3/15
6
 * Time: 7:12 PM.
7
 */
8
namespace PHPHub\Transformers;
9
10
use Illuminate\Database\Eloquent\Model;
11
use League\Fractal\TransformerAbstract;
12
13
abstract class BaseTransformer extends TransformerAbstract
14
{
15
    public function transform(Model $model)
16
    {
17
        if ($model instanceof HasPresenter) {
0 ignored issues
show
Bug introduced by
The class PHPHub\Transformers\HasPresenter does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
18
            $model = app('autopresenter')->decorate($model);
19
        }
20
21
        $transformData = $this->transformData($model);
22
23
        $data = array_filter($transformData, function ($v) {
24
            if (is_null($v)) {
25
                return false;
26
            }
27
28
            return true;
29
        });
30
31
        // 转换 null 字段为空字符串
32
        foreach (array_keys($model->toArray()) as $key) {
33
            if (! isset($data[$key])) {
34
                $data[$key] = '';
35
                continue;
36
            }
37
            if (is_null($data[$key])) {
38
                $data[$key] = '';
39
            }
40
        }
41
42
        return $data;
43
    }
44
45
    abstract public function transformData($model);
46
}
47