Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
NotEqualTo
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Db\Sql\Predicate;
15
16use Pop\Db\Sql\AbstractSql;
17
18/**
19 * Not Equal To predicate class
20 *
21 * @category   Pop
22 * @package    Pop\Db
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    6.5.0
27 */
28class NotEqualTo extends AbstractPredicate
29{
30
31    /**
32     * Constructor
33     *
34     * Instantiate the NOT EQUAL TO predicate set object
35     *
36     * @param  array  $values
37     * @param  string $conjunction
38     * @throws Exception
39     */
40    public function __construct(array $values, string $conjunction = 'AND')
41    {
42        $this->format = '%1 != %2';
43        parent::__construct($values, $conjunction);
44    }
45
46    /**
47     * Render the predicate string
48     *
49     *
50     * @param  AbstractSql $sql
51     * @throws Exception
52     * @return string
53     */
54    public function render(AbstractSql $sql): string
55    {
56        if (count($this->values) != 2) {
57            throw new Exception('Error: The values array must have 2 values in it.');
58        }
59
60        [$column, $value] = $this->values;
61
62        return '(' . str_replace(['%1', '%2'], [$sql->quoteId($column), $sql->quote($value)], $this->format) . ')';
63    }
64
65}