Issues (12)

src/Console/Commands/HasTablesClassesMap.php (1 issue)

Severity
1
<?php
2
3
namespace LaraGeoData\Console\Commands;
4
5
use LaraGeoData\Database\Tables\Geonames;
6
use LaraGeoData\Database\Tables\GeoTable;
7
use LaraGeoData\Database\Tables\Postalcodes;
8
9
trait HasTablesClassesMap
10
{
11
    /**
12
     * Map describe command type and table class.
13
     *
14
     * @var array
15
     */
16
    protected array $classesMap = [
17
        'geonames'    => Geonames::class,
18
        'postalcodes' => Postalcodes::class,
19
    ];
20
21
    /**
22
     * @param string $type
23
     * @return GeoTable
24
     * @throws \Exception
25
     */
26 14
    public function getTableClassNameByType(string $type)
27
    {
28 14
        if (!isset($this->classesMap[$type]) || !is_a($this->classesMap[$type], GeoTable::class, true)) {
29 1
            throw new \Exception("Class for type [{$type}] not found.");
30
        }
31
32 13
        return $this->classesMap[$type];
33
    }
34
35
    /**
36
     * @param string $type
37
     * @param        ...$attributes
38
     * @return mixed
39
     * @throws \Exception
40
     */
41 14
    public function makeTableObjectNameByType(string $type, ...$attributes): GeoTable
42
    {
43 14
        $tableClassName = $this->getTableClassNameByType($type);
44
45
        /** @psalm-suppress UndefinedClass */
46 13
        return new $tableClassName(...$attributes);
0 ignored issues
show
The call to LaraGeoData\Database\Tab...GeoTable::__construct() has too many arguments starting with $attributes. ( Ignorable by Annotation )

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

46
        return /** @scrutinizer ignore-call */ new $tableClassName(...$attributes);

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...
47
    }
48
}
49