Completed
Push — master ( 785bde...8b4d11 )
by Freek
01:29
created

Join::__invoke()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 4
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
/*
8
 * Join all items from the collection using a string. The final items can use a separate glue string.
9
 *
10
 */
11
class Join
12
{
13
    public function __invoke()
14
    {
15
        return function (string $glue, string $finalGlue = ''): string {
16
            if ($finalGlue === '') {
17
                return $this->implode($glue);
0 ignored issues
show
Bug introduced by
The method implode() does not seem to exist on object<Spatie\CollectionMacros\Macros\Join>.

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...
18
            };
19
20
            if ($this->count() === 0) {
0 ignored issues
show
Bug introduced by
The method count() does not seem to exist on object<Spatie\CollectionMacros\Macros\Join>.

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...
21
                return '';
22
            }
23
24
            if ($this->count() === 1) {
0 ignored issues
show
Bug introduced by
The method count() does not seem to exist on object<Spatie\CollectionMacros\Macros\Join>.

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...
25
                return $this->last();
0 ignored issues
show
Bug introduced by
The method last() does not seem to exist on object<Spatie\CollectionMacros\Macros\Join>.

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...
26
            }
27
28
            $collection = new Collection($this->items);
0 ignored issues
show
Bug introduced by
The property items does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
30
            $finalItem = $collection->pop();
31
32
            return $collection->implode($glue).$finalGlue.$finalItem;
33
        };
34
    }
35
}
36