AshPowell /
APAnalytics
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace AshPowell\APAnalytics\Traits; |
||||||
| 4 | |||||||
| 5 | use App\User; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 6 | use Illuminate\Support\Str; |
||||||
| 7 | use \Carbon\Carbon; |
||||||
| 8 | use \Carbon\CarbonPeriod; |
||||||
| 9 | |||||||
| 10 | trait IsAnalytic |
||||||
| 11 | { |
||||||
| 12 | public function initializeIsAnalytic() |
||||||
| 13 | { |
||||||
| 14 | $this->connection = config('apanalytics.db_connection'); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 15 | $this->collection = Str::plural(Str::before($this->getTable(), '_analytic')); |
||||||
|
0 ignored issues
–
show
It seems like
getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 16 | $this->dates = ['created_at', 'updated_at']; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 17 | $this->guarded = []; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 18 | } |
||||||
| 19 | |||||||
| 20 | public function canViewCollection(User $user = null) |
||||||
| 21 | { |
||||||
| 22 | if (app()->runningInConsole()) { |
||||||
|
0 ignored issues
–
show
The method
runningInConsole() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 23 | return true; |
||||||
| 24 | } |
||||||
| 25 | |||||||
| 26 | if (! $user) { |
||||||
| 27 | return false; |
||||||
| 28 | } |
||||||
| 29 | |||||||
| 30 | return $user->isAnyAdmin(); |
||||||
| 31 | } |
||||||
| 32 | |||||||
| 33 | /** |
||||||
| 34 | * Returns the month on month analytic count |
||||||
| 35 | * |
||||||
| 36 | * @param string $period |
||||||
| 37 | * @return Array |
||||||
| 38 | */ |
||||||
| 39 | public static function getCumulativeGrowthData($period = 6) |
||||||
| 40 | { |
||||||
| 41 | $endDate = now(); |
||||||
| 42 | $startDate = $endDate->copy()->subMonths($period); |
||||||
|
0 ignored issues
–
show
It seems like
$period can also be of type string; however, parameter $value of Carbon\Carbon::subMonths() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 43 | $period = CarbonPeriod::create($startDate, "1 month", $endDate); |
||||||
| 44 | |||||||
| 45 | $output = []; |
||||||
| 46 | foreach ($period as $date) { |
||||||
| 47 | $date = $date->format('d-m-Y'); |
||||||
|
0 ignored issues
–
show
The method
format() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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...
|
|||||||
| 48 | $output[$date] = (new static)->getCountForDate($date, 'd-m-Y'); |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | return $output; |
||||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | /** |
||||||
| 55 | * Returns the analytic count for the specified month |
||||||
| 56 | * |
||||||
| 57 | * @param String $date |
||||||
| 58 | * @param String $format |
||||||
| 59 | * @return Int |
||||||
| 60 | */ |
||||||
| 61 | public static function getCountForDate($date, $format) |
||||||
| 62 | { |
||||||
| 63 | $currentDate = Carbon::createFromFormat($format, $date); |
||||||
| 64 | |||||||
| 65 | $currentCount = (new static) |
||||||
| 66 | ->where('created_at', '<=', $currentDate) |
||||||
|
0 ignored issues
–
show
It seems like
where() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 67 | ->count(); |
||||||
| 68 | |||||||
| 69 | return $currentCount; |
||||||
| 70 | } |
||||||
| 71 | } |
||||||
| 72 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths