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
LemmaTermValidator
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikibase\Lexeme\DataAccess\ChangeOp\Validation;
4
5use Wikibase\Repo\Validators\CompositeValidator;
6use Wikibase\Repo\Validators\RegexValidator;
7use Wikibase\Repo\Validators\StringLengthValidator;
8use Wikibase\Repo\Validators\TypeValidator;
9
10/**
11 * @license GPL-2.0-or-later
12 */
13class LemmaTermValidator {
14
15    public const LEMMA_MAX_LENGTH = 1000;
16
17    /**
18     * @var CompositeValidator
19     */
20    private $validator;
21
22    /**
23     * @param int $maxTermLength LEMMA_MAX_LENGTH
24     */
25    public function __construct( $maxTermLength ) {
26        // TODO: validate UTF8
27        $this->validator = new CompositeValidator(
28            [
29                new TypeValidator( 'string' ),
30                new StringLengthValidator( 1, $maxTermLength, 'mb_strlen' ),
31                new RegexValidator( '/^\s|[\v\t]|\s$/u', true ),
32            ],
33            true
34        );
35    }
36
37    public function validate( $value ) {
38        return $this->validator->validate( $value );
39    }
40
41}