Completed
Push — master ( e2b114...270eeb )
by Freek
05:03
created

src/Macros/Join.php (5 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
class Join
11
{
12
    public function __invoke()
13
    {
14
        return function (string $glue, string $finalGlue = ''): string {
15
            if ($finalGlue === '') {
16
                return $this->implode($glue);
0 ignored issues
show
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...
17
            }
18
19
            if ($this->count() === 0) {
0 ignored issues
show
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...
20
                return '';
21
            }
22
23
            if ($this->count() === 1) {
0 ignored issues
show
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...
24
                return $this->last();
0 ignored issues
show
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...
25
            }
26
27
            $collection = new Collection($this->items);
0 ignored issues
show
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...
28
29
            $finalItem = $collection->pop();
30
31
            return $collection->implode($glue).$finalGlue.$finalItem;
32
        };
33
    }
34
}
35