StringArgumentType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A parse() 0 2 1
A validate() 0 14 6
1
<?php
2
/**
3
 * Livia
4
 * Copyright 2017-2019 Charlotte Dunois, All Rights Reserved
5
 *
6
 * Website: https://charuru.moe
7
 * License: https://github.com/CharlotteDunois/Livia/blob/master/LICENSE
8
*/
9
10
namespace CharlotteDunois\Livia\Types;
11
12
/**
13
 * {@inheritdoc}
14
 * @internal
15
 */
16
class StringArgumentType extends ArgumentType {
17
    /**
18
     * @internal
19
     */
20
    function __construct(\CharlotteDunois\Livia\Client $client) {
21
        parent::__construct($client, 'string');
22
    }
23
    
24
    /**
25
     * {@inheritdoc}
26
     * @return bool|string|\React\Promise\ExtendedPromiseInterface
27
     */
28
    function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
29
        if(\mb_strlen($value) === 0) {
30
            return false;
31
        }
32
        
33
        if($arg->min !== null && \mb_strlen($value) < $arg->min) {
34
            return 'Please enter something above or exactly '.$arg->min.' characters in length.';
35
        }
36
        
37
        if($arg->max !== null && \mb_strlen($value) > $arg->max) {
38
            return 'Please enter a number below or exactly '.$arg->max.' characters in length.';
39
        }
40
        
41
        return true;
42
    }
43
    
44
    /**
45
     * {@inheritdoc}
46
     * @return mixed|null|\React\Promise\ExtendedPromiseInterface
47
     */
48
    function parse(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
49
        return $value;
50
    }
51
}
52