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
Exists
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
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Db\Sql\Predicate;
16
17use Pop\Db\Sql\AbstractSql;
18
19/**
20 * Exists predicate class
21 *
22 * @category   Pop
23 * @package    Pop\Db
24 * @author     Nick Sagona, III <nick@popphp.org>
25 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
26 * @license    https://www.popphp.org/license     New BSD License
27 * @version    7.0.0
28 */
29class Exists extends AbstractPredicate
30{
31
32    /**
33     * Constructor
34     *
35     * Instantiate the EXISTS predicate set object
36     *
37     * @param  mixed  $values
38     * @param  string $conjunction
39     * @throws Exception
40     */
41    public function __construct(mixed $values, string $conjunction = 'AND')
42    {
43        $this->format = 'EXISTS (%1)';
44        parent::__construct($values, $conjunction);
45    }
46
47    /**
48     * Render the predicate string
49     *
50     * @param  AbstractSql $sql
51     * @throws Exception
52     * @return string
53     */
54    public function render(AbstractSql $sql): string
55    {
56        if (!($this->values instanceof AbstractSql)) {
57            throw new Exception('Error: The value must be a Sql\Select instance.');
58        }
59
60        static::assertNoSubqueryAlias($this->values);
61
62        return '(' . str_replace('%1', (string)$this->values, $this->format) . ')';
63    }
64
65}