dev-think-one /
laravel-myriad-data-store
| 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
|
|||
| 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
|
|||
| 44 | 2 | $myriadModel->title_id = $item['Title_ID']; |
|
|
0 ignored issues
–
show
|
|||
| 45 | 2 | $myriadModel->number = $item['IssueNumber']; |
|
|
0 ignored issues
–
show
|
|||
| 46 | 2 | $myriadModel->publication_date = $item['PublicationDate']; |
|
|
0 ignored issues
–
show
|
|||
| 47 | 2 | $myriadModel->save(); |
|
| 48 | 2 | $count++; |
|
| 49 | } |
||
| 50 | |||
| 51 | 2 | return $count; |
|
| 52 | } |
||
| 53 | } |
||
| 54 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: