AshPowell /
APAnalytics
| 1 | <?php |
||||
| 2 | |||||
| 3 | use AshPowell\APAnalytics\APAnalytics; |
||||
| 4 | use Illuminate\Support\Carbon; |
||||
| 5 | use MongoDB\BSON\UTCDateTime; |
||||
| 6 | |||||
| 7 | if (! function_exists('analytics')) { |
||||
| 8 | function analytics(): APAnalytics |
||||
| 9 | { |
||||
| 10 | return app(APAnalytics::class); |
||||
| 11 | } |
||||
| 12 | } |
||||
| 13 | |||||
| 14 | if (! function_exists('trackEvent')) { |
||||
| 15 | /** |
||||
| 16 | * Access event dispatch of event tracker direct. |
||||
| 17 | * @param mixed $event |
||||
| 18 | * @param mixed $collection |
||||
| 19 | * @param mixed $items |
||||
| 20 | * @param mixed $params |
||||
| 21 | * @param null|mixed $userId |
||||
| 22 | */ |
||||
| 23 | function trackEvent($collection, $items, $userId = null, $params = []) |
||||
|
0 ignored issues
–
show
|
|||||
| 24 | { |
||||
| 25 | return analytics()->track($collection, $items, $userId, $params); |
||||
|
0 ignored issues
–
show
Are you sure the usage of
analytics()->track($coll...tems, $userId, $params) targeting AshPowell\APAnalytics\APAnalytics::track() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 26 | } |
||||
| 27 | } |
||||
| 28 | |||||
| 29 | if (! function_exists('showEvents')) { |
||||
| 30 | /** |
||||
| 31 | * Access event dispatch of event tracker direct. |
||||
| 32 | * @param mixed $event |
||||
| 33 | * @param mixed $collection |
||||
| 34 | * @param mixed $items |
||||
| 35 | * @param mixed $params |
||||
| 36 | * @param null|mixed $userId |
||||
| 37 | * @param null|mixed $timeframe |
||||
| 38 | * @param null|mixed $filters |
||||
| 39 | * @param mixed $interval |
||||
| 40 | */ |
||||
| 41 | function showEvents($collection, $interval = 'count', $timeframe = null, $filters = null) |
||||
| 42 | { |
||||
| 43 | return analytics()->show($collection, $interval, $timeframe, $filters); |
||||
| 44 | } |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | if (! function_exists('is_countable')) { |
||||
| 48 | function is_countable($c) |
||||
| 49 | { |
||||
| 50 | return is_array($c) || $c instanceof Countable; |
||||
| 51 | } |
||||
| 52 | } |
||||
| 53 | |||||
| 54 | if (! function_exists('mongoTime')) { |
||||
| 55 | /** |
||||
| 56 | * Returns time in MongoDb Time. |
||||
| 57 | * @param null|mixed $time |
||||
| 58 | */ |
||||
| 59 | function mongoTime($time = null) |
||||
| 60 | { |
||||
| 61 | $time = ($time) ? Carbon::parse($time) : now(); |
||||
| 62 | |||||
| 63 | return new UTCDateTime($time); |
||||
|
0 ignored issues
–
show
It seems like
$time can also be of type Illuminate\Support\Carbon; however, parameter $milliseconds of MongoDB\BSON\UTCDateTime::__construct() 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...
|
|||||
| 64 | } |
||||
| 65 | } |
||||
| 66 | |||||
| 67 | if (! function_exists('valid_json')) { |
||||
| 68 | function valid_json($value) |
||||
| 69 | { |
||||
| 70 | if (! is_string($value)) { |
||||
| 71 | return false; |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | json_decode($value); |
||||
| 75 | |||||
| 76 | return json_last_error() === JSON_ERROR_NONE; |
||||
| 77 | } |
||||
| 78 | } |
||||
| 79 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.