Group   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A users() 0 4 1
A updateOrCreateFromChat() 0 15 1
1
<?php
2
3
namespace Transmissor\Models;
4
5
// use Transmissor\Traits\HasCurrency;
6
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Transmissor\Models\Model.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
8
class Group extends Model
9
{
10
11
    // use HasCurrency; @todo
12
13
    const UPDATED_AT = null;
14
15
    protected $guarded = [];
16
17
    public function users()
18
    {
19
        return $this->belongsToMany(User::class);
20
    }
21
22
    public static function updateOrCreateFromChat($chat, string $language = 'es', string $currency = 'eur')
23
    {
24
        $group = self::updateOrCreate(
0 ignored issues
show
Bug introduced by
The method updateOrCreate() does not exist on Transmissor\Models\Group. Did you maybe mean updateOrCreateFromChat()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
25
            [
26
            'telegram_id' => $chat['id'],
27
            'type' => $chat['type'],
28
            ], [
29
            'title' => $chat['title'],
30
            'language' => $language,
31
            'currency' => $currency,
32
            ]
33
        );
34
35
        return $group;
36
    }
37
38
}
39