Passed
Push — 0.7.0 ( 941781...effe46 )
by Alexander
12:00 queued 11s
created

Enumerates::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Collections\Traits;
24
25
/**
26
 * Trait.
27
 * 
28
 * @author Alexander Campo <[email protected]>
29
 */
30
trait Enumerates
31
{
32
    /**
33
     * Create a new collection instance if the value isn't one already.
34
     * 
35
     * @param  mixed  $items
36
     * 
37
     * @return static
38
     */
39
    public static function make($items = [])
40
    {
41
        return new static($items);
0 ignored issues
show
Unused Code introduced by
The call to Syscodes\Collections\Tra...umerates::__construct() has too many arguments starting with $items. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        return /** @scrutinizer ignore-call */ new static($items);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
42
    }
43
44
    /**
45
     * Create a collection of all elements that do not pass a given truth test.
46
     * 
47
     * @param \callable|mixed  $callable
0 ignored issues
show
Bug introduced by
The type callable was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
     * 
49
     * @return static
50
     */
51
    public function reject($callback = true)
52
    {
53
        $useAsCallable = $this->useAsCallable($callback);
54
55
        return $this->filter(function($value, $key) use ($callback, $useAsCallable) {
0 ignored issues
show
Bug introduced by
It seems like filter() 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 ignore-call  annotation

55
        return $this->/** @scrutinizer ignore-call */ filter(function($value, $key) use ($callback, $useAsCallable) {
Loading history...
56
            return $useAsCallable
57
                ? ! $callback($value, $key)
58
                : $value != $callback;
59
        });
60
    }
61
62
    /**
63
     * Determine if the given value is callable, but not a string.
64
     * 
65
     * @param  mixed  $value
66
     * 
67
     * @return bool
68
     */
69
    protected function useAsCallable($value)
70
    {
71
        return ! is_string($value) && is_callable($value);
72
    }
73
}
74