Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ItemIdListDeserializer
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deserialize
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace Wikibase\Lexeme\Presentation\ChangeOp\Deserialization;
4
5use Wikibase\DataModel\Entity\EntityIdParsingException;
6use Wikibase\DataModel\Entity\ItemId;
7use Wikibase\DataModel\Entity\ItemIdParser;
8use Wikibase\Lexeme\MediaWiki\Api\Error\JsonFieldIsNotAnItemId;
9
10/**
11 * @license GPL-2.0-or-later
12 */
13class ItemIdListDeserializer {
14
15    /**
16     * @var ItemIdParser
17     */
18    private $itemIdParser;
19
20    public function __construct( ItemIdParser $itemIdParser ) {
21        $this->itemIdParser = $itemIdParser;
22    }
23
24    /**
25     * @param mixed $serialization
26     * @param ValidationContext $validationContext
27     * @return ItemId[]
28     */
29    public function deserialize( $serialization, ValidationContext $validationContext ) {
30        $itemIdList = [];
31
32        foreach ( $serialization as $index => $itemId ) {
33            $context = $validationContext->at( $index );
34            try {
35                $itemIdList[] = $this->itemIdParser->parse( $itemId );
36            } catch ( EntityIdParsingException $ex ) {
37                $context->addViolation( new JsonFieldIsNotAnItemId( $itemId ) );
38            }
39        }
40
41        return $itemIdList;
42    }
43
44}