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
NotIn
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
4
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%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
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 In 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 NotIn extends AbstractPredicate
29{
30
31    /**
32     * Constructor
33     *
34     * Instantiate the NOT IN 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 NOT IN (%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        if (!is_array($this->values[1])) {
60            throw new Exception('Error: The 2nd value must be an array of values.');
61        }
62
63        [$column, $values] = $this->values;
64
65        $values = array_map([$sql, 'quote'], $values);
66
67        return '(' . str_replace(['%1', '%2'], [$sql->quoteId($column), implode(', ', $values)], $this->format) . ')';
68    }
69
70}