Issues (52)

src/Commands/CurrencyCleanup.php (2 issues)

1
<?php
2
3
4
namespace Turahe\Master\Commands;
5
6
use Illuminate\Console\Command;
7
8
class CurrencyCleanup extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'currency:cleanup';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Cleanup currency cache';
23
24
    /**
25
     * Currency instance
26
     *
27
     * @var \Torann\Currency\Currency
0 ignored issues
show
The type Torann\Currency\Currency 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...
28
     */
29
    protected $currency;
30
31
    /**
32
     * Create a new command instance.
33
     */
34
    public function __construct()
35
    {
36
        $this->currency = app('currency');
0 ignored issues
show
Documentation Bug introduced by
It seems like app('currency') can also be of type Illuminate\Contracts\Foundation\Application. However, the property $currency is declared as type Torann\Currency\Currency. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
37
38
        parent::__construct();
39
    }
40
41
    /**
42
     * Execute the console command for Laravel 5.4 and below
43
     *
44
     * @return void
45
     */
46
    public function fire()
47
    {
48
        $this->handle();
49
    }
50
51
    /**
52
     * Execute the console command.
53
     *
54
     * @return void
55
     */
56
    public function handle()
57
    {
58
        // Clear cache
59
        $this->currency->clearCache();
60
        $this->comment('Currency cache cleaned.');
61
62
        // Force the system to rebuild cache
63
        $this->currency->getCurrencies();
64
        $this->comment('Currency cache rebuilt.');
65
    }
66
}
67