• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LM-Commons / LmcUser / 9685950326

26 Jun 2024 07:59PM UTC coverage: 90.563% (-0.05%) from 90.609%
9685950326

push

github

web-flow
Merge pull request #85 from visto9259/fix_51

To fix #51

4 of 4 new or added lines in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

1593 of 1759 relevant lines covered (90.56%)

3.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/Validator/AbstractRecord.php
1
<?php
2

3
namespace LmcUser\Validator;
4

5
use Laminas\Validator\AbstractValidator;
6
use LmcUser\Mapper\UserInterface;
7

8
abstract class AbstractRecord extends AbstractValidator
9
{
10
    /**
11
     * Error constants
12
     */
13
    const ERROR_NO_RECORD_FOUND = 'noRecordFound';
14
    const ERROR_RECORD_FOUND    = 'recordFound';
15

16
    /**
17
     * @var array Message templates
18
     */
19
    protected $messageTemplates = array(
20
        self::ERROR_NO_RECORD_FOUND => "No record matching the input was found",
21
        self::ERROR_RECORD_FOUND    => "A record matching the input was found",
22
    );
23

24
    /**
25
     * @var UserInterface
26
     */
27
    protected $mapper;
28

29
    /**
30
     * @var string
31
     */
32
    protected $key;
33

34
    /**
35
     * Required options are:
36
     *  - key     Field to use, 'email' or 'username'
37
     */
38
    public function __construct(array $options)
4✔
39
    {
40
        if (!array_key_exists('key', $options)) {
4✔
41
            throw new Exception\InvalidArgumentException('No key provided');
1✔
42
        }
43

44
        $this->setKey($options['key']);
3✔
45

46
        parent::__construct($options);
3✔
47
    }
48

49
    /**
50
     * getMapper
51
     *
52
     * @return UserInterface
53
     */
54
    public function getMapper()
1✔
55
    {
56
        return $this->mapper;
1✔
57
    }
58

59
    /**
60
     * setMapper
61
     *
62
     * @param  UserInterface $mapper
63
     * @return AbstractRecord
64
     */
65
    public function setMapper(UserInterface $mapper)
3✔
66
    {
67
        $this->mapper = $mapper;
3✔
68
        return $this;
3✔
69
    }
70

71
    /**
72
     * Get key.
73
     *
74
     * @return string
75
     */
76
    public function getKey()
1✔
77
    {
78
        return $this->key;
1✔
79
    }
80

81
    /**
82
     * Set key.
83
     *
84
     * @param string $key
85
     */
86
    public function setKey($key)
3✔
87
    {
88
        $this->key = $key;
3✔
89
        return $this;
3✔
90
    }
91

92
    /**
93
     * Grab the user from the mapper
94
     *
95
     * @param  string $value
96
     * @return mixed
97
     */
98
    protected function query($value)
3✔
99
    {
100
        $result = false;
3✔
101

102
        switch ($this->getKey()) {
3✔
103
            case 'email':
3✔
104
                $result = $this->getMapper()->findByEmail($value);
1✔
105
                break;
1✔
106

107
            case 'username':
2✔
108
                $result = $this->getMapper()->findByUsername($value);
1✔
109
                break;
1✔
110

111
            default:
112
                throw new \Exception('Invalid key used in LmcUser validator');
1✔
UNCOV
113
                break;
×
114
        }
115

116
        return $result;
2✔
117
    }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc