Completed
Branch master (cc471b)
by Vitaliy
04:22
created

InvalidDataSourceException::forSrc()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 13
nc 3
nop 1
1
<?php
2
3
namespace ViewComponents\Eloquent\Exception;
4
5
use InvalidArgumentException;
6
7
class InvalidDataSourceException extends InvalidArgumentException implements EloquentDataProcessingExceptionInterface
8
{
9
    public static function forSrc($src)
10
    {
11
        if (is_string($src)) {
12
            $srcName = $src;
13
        } elseif (is_object($src)) {
14
            $srcName = get_class($src) . ' instance';
15
        } else {
16
            $srcName = gettype($src);
17
        }
18
        return new static(
19
            'Invalid data source, EloquentDataProvider constructor should be used with'
20
            . ' Illuminate\Database\Eloquent\Builder instance'
21
            . ' or Illuminate\Database\Query\Builder instance'
22
            . ' or class name of target Eloquent model'
23
            . "($srcName given)."
24
        );
25
    }
26
}
27