Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ConstraintSerializer
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
3
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
 serialize
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace WikibaseQuality\ConstraintReport;
4
5/**
6 * @author Lucas Werkmeister
7 * @license GPL-2.0-or-later
8 */
9class ConstraintSerializer {
10
11    /**
12     * @var bool
13     */
14    private $serializeConstraintParameters;
15
16    /**
17     * @param bool $serializeConstraintParameters Whether to serialize constraint parameters or not.
18     */
19    public function __construct( $serializeConstraintParameters = true ) {
20        $this->serializeConstraintParameters = $serializeConstraintParameters;
21    }
22
23    /**
24     * @param Constraint $constraint
25     * @return array
26     */
27    public function serialize( Constraint $constraint ) {
28        $serialization = [
29            'id' => $constraint->getConstraintId(),
30            'pid' => $constraint->getPropertyId()->getSerialization(),
31            'qid' => $constraint->getConstraintTypeItemId(),
32        ];
33        if ( $this->serializeConstraintParameters ) {
34            $serialization['params'] = $constraint->getConstraintParameters();
35        }
36        return $serialization;
37    }
38
39}