src/Psalm/Type/Algebra.php
public static function getTruthsFromFormula(
        array $clauses,
        array &$cond_referenced_var_ids = []
    ) {
        $truths = [];

        if (empty($clauses)) {
            return [];
        }

        foreach ($clauses as $clause) {
            if (!$clause->reconcilable) {
                continue;
            }

            foreach ($clause->possibilities as $var => $possible_types) {
                // if there's only one possible type, return it
                if (count($clause->possibilities) === 1 && count($possible_types) === 1) {
                    if (isset($truths[$var])) {
                        $truths[$var][] = [array_pop($possible_types)];
                    } else {
                        $truths[$var] = [[array_pop($possible_types)]];
                    }
                } elseif (count($clause->possibilities) === 1) {
                    // if there's only one active clause, return all the non-negation clause members ORed together
                    $things_that_can_be_said = array_filter(
                        $possible_types,
                        /**
                         * @param  string $possible_type
                         *
                         * @return bool
                         *
                         * @psalm-suppress MixedOperand
                         */
                        function ($possible_type) {
                            return $possible_type[0] !== '!';
                        }
                    );

                    if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) {
                        $things_that_can_be_said = array_unique($things_that_can_be_said);

                        if ($clause->generated && count($possible_types) > 1) {
                            unset($cond_referenced_var_ids[$var]);
                        }

                        /** @var array<int, string> $things_that_can_be_said */
                        $truths[$var] = [$things_that_can_be_said];
                    }
                }
            }
        }

        return $truths;
    }
public static function getTruthsFromFormula(
        array $clauses,
        array &$cond_referenced_var_ids = []
    ) {
        $truths = [];

        if (empty($clauses)) {
            return [];
        }

        foreach ($clauses as $clause) {
            if (!$clause->reconcilable) {
                continue;
            }

            foreach ($clause->possibilities as $var => $possible_types) {
                // if there's only one possible type, return it
                if (count($clause->possibilities) === 1 && count($possible_types) === 1) {
                    if (isset($truths[$var])) {
                        $truths[$var][] = [array_pop($possible_types)];
                    } else {
                        $truths[$var] = [[array_pop($possible_types)]];
                    }
                } elseif (count($clause->possibilities) === 1) {
                    // if there's only one active clause, return all the non-negation clause members ORed together
                    $things_that_can_be_said = array_filter(
                        $possible_types,
                        /**
                         * @param  string $possible_type
                         *
                         * @return bool
                         *
                         * @psalm-suppress MixedOperand
                         */
                        function ($possible_type) {
                            return $possible_type[0] !== '!';
                        }
                    );

                    if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) {
                        $things_that_can_be_said = array_unique($things_that_can_be_said);

                        if ($clause->generated && count($possible_types) > 1) {
                            unset($cond_referenced_var_ids[$var]);
                        }

                        /** @var array<int, string> $things_that_can_be_said */
                        $truths[$var] = [$things_that_can_be_said];
                    }
                }
            }
        }

        return $truths;
    }
public static function getTruthsFromFormula ( array $ clauses , array & $ cond_referenced_var_ids = [ ] ) { $ truths = [ ] ; if ( empty ( $ clauses ) ) { return [ ] ; } foreach ( $ clauses as $ clause ) { if ( ! $ clause -> reconcilable ) { continue ; } foreach ( $ clause -> possibilities as $ var => $ possible_types ) { // if there's only one possible type, return it if ( count ( $ clause -> possibilities ) === 1 && count ( $ possible_types ) === 1 ) { if ( isset ( $ truths [ $ var ] ) ) { $ truths [ $ var ] [ ] = [ array_pop ( $ possible_types ) ] ; } else { $ truths [ $ var ] = [ [ array_pop ( $ possible_types ) ] ] ; } } elseif ( count ( $ clause -> possibilities ) === 1 ) { // if there's only one active clause, return all the non-negation clause members ORed together $ things_that_can_be_said = array_filter ( $ possible_types , /**
                         * @param  string $possible_type
                         *
                         * @return bool
                         *
                         * @psalm-suppress MixedOperand
                         */ function ( $ possible_type ) { return $ possible_type [ 0 ] !== '!' ; } ) ; if ( $ things_that_can_be_said && count ( $ things_that_can_be_said ) === count ( $ possible_types ) ) { $ things_that_can_be_said = array_unique ( $ things_that_can_be_said ) ; if ( $ clause -> generated && count ( $ possible_types ) > 1 ) { unset ( $ cond_referenced_var_ids [ $ var ] ) ; } /** @var array<int, string> $things_that_can_be_said */ $ truths [ $ var ] = [ $ things_that_can_be_said ] ; } } } } return $ truths ; }
Look for clauses with only one possible value

@param  array<int, Clause>  $clauses
@param  array<string, bool> $cond_referenced_var_ids

@return array<string, array<int, array<int, string>>>
Look for clauses with only one possible value