DownloadMyriadIssues   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 41
ccs 25
cts 25
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 24 4
A defaultCollectionFormat() 0 8 1
1
<?php
2
3
namespace MyriadDataStore\Actions;
4
5
use Illuminate\Support\Carbon;
6
use Illuminate\Support\Str;
7
use MyriadDataStore\Models\MyriadIssue;
8
use MyriadSoap\Exceptions\UnexpectedTypeException;
9
use MyriadSoap\MyriadSoap;
10
11
class DownloadMyriadIssues
12
{
13
    use UsesCollectionFormat;
14
15
    public static ?array $collectionFormat = null;
16
17 2
    protected function defaultCollectionFormat(): array
18
    {
19 2
        return [
20 2
            'Issue_ID'        => fn ($i) => (int) tap($i, fn () => throw_if(!is_numeric($i), UnexpectedTypeException::class)),
21 2
            'Title_ID'        => fn ($i) => (int) tap($i, fn () => throw_if(!is_numeric($i), UnexpectedTypeException::class)),
22 2
            'Issue'           => fn ($i) => (string) $i,
23 2
            'IssueNumber'     => fn ($i) => (int) tap($i, fn () => throw_if(!is_numeric($i), UnexpectedTypeException::class)),
24 2
            'PublicationDate' => fn ($i) => Carbon::createFromFormat('Y-m-d', $i),
25 2
        ];
26
    }
27
28 2
    public function execute(?int $titleId = null): int
29
    {
30 2
        if ($titleId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $titleId of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
31 1
            $formattedCollection = MyriadSoap::SOAP_getIssuesForTitle_Collection(['Title_ID' => $titleId], $this->collectionFormat(), 'Issue');
32
        } else {
33 1
            $formattedCollection = MyriadSoap::SOAP_getIssues_Collection([], $this->collectionFormat());
34
        }
35
36 2
        $count = 0;
37 2
        foreach ($formattedCollection as $item) {
38 2
            $myriadModel = MyriadIssue::find($item['Issue_ID']);
39 2
            if (!$myriadModel) {
40 2
                $myriadModel     = new MyriadIssue;
41 2
                $myriadModel->id = $item['Issue_ID'];
42
            }
43 2
            $myriadModel->name             = Str::limit($item['Issue'], 252);
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on MyriadDataStore\Models\MyriadIssue. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
44 2
            $myriadModel->title_id         = $item['Title_ID'];
0 ignored issues
show
Bug introduced by
The property title_id does not exist on MyriadDataStore\Models\MyriadIssue. Did you mean title?
Loading history...
45 2
            $myriadModel->number           = $item['IssueNumber'];
0 ignored issues
show
Bug introduced by
The property number does not seem to exist on MyriadDataStore\Models\MyriadIssue. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
46 2
            $myriadModel->publication_date = $item['PublicationDate'];
0 ignored issues
show
Bug introduced by
The property publication_date does not seem to exist on MyriadDataStore\Models\MyriadIssue. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
47 2
            $myriadModel->save();
48 2
            $count++;
49
        }
50
51 2
        return $count;
52
    }
53
}
54