Fail proof setter for $fetch_flags

@param $option

@return $this
161959
public function setFetchFlagsOption($option) {
        if (is_bool($option)) {
            $this->fetch_flags = $option;
        } elseif (is_null($option)) {
            $config = config('imap.options.fetch_flags', true);
            $this->fetch_flags = is_bool($config) ? $config : true;
        }

        return $this;
    }
477659
private function buildFetchCallback( $fetchOptions, $flatten )
    {

        $original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
        $new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );

        // nothing has changed - don't need to change the callback
        if( $original === $new ) {
            return false;
        }

        // only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)
        $this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM;

        // types and keys
        // determine types - this could be enabled to automatically convert types (to something other than a string)
        // off by default as the performance hit has yet to be determined
        if( $fetchOptions & self::TYPE_DETECT ) {

            $typeCallbacks = $this->getFieldTypeCallbacks();
            if( $this->fetchType === PGSQL_ASSOC ) {
                $keys = array_keys( $typeCallbacks );
            } else {
                $keys = range(0, count($typeCallbacks) - 1);
            }

            // flatten
            if( $flatten ) {

                $typeCallback = array_pop( $typeCallbacks );
                $this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) {
                    return call_user_func( $typeCallback, $row[0] );
                };

            } else {

                $this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) {
                    return array_combine(
                        $keys,
                        array_map( 'call_user_func', $typeCallbacks, $row )
                    );
                };

            }

        } elseif( $flatten ) {

            $this->fetchCallback = function( $row ) {
                return array_shift( $row );
            };

        } else {

            $this->fetchCallback = function( $row ) {
                return $row;
            };

        }

        return true;

    }
898295
function unset_option( $option, $flush = false ) {
            $this->_logger->entrance( 'option = ' . $option );

            if ( is_array( $this->_options ) ) {
                if ( ! isset( $this->_options[ $option ] ) ) {
                    return;
                }

                unset( $this->_options[ $option ] );

            } else if ( is_object( $this->_options ) ) {
                if ( ! isset( $this->_options->{$option} ) ) {
                    return;
                }

                unset( $this->_options->{$option} );
            }

            if ( $flush ) {
                $this->store();
            }
        }
1357513
public function stream_set_option($option, $arg1, $arg2)
    {
        switch ($option) {
            case STREAM_OPTION_BLOCKING:
                // This works for the local adapter. It doesn't do anything for
                // memory streams.
                return stream_set_blocking($this->handle, $arg1);

            case STREAM_OPTION_READ_TIMEOUT:
                return  stream_set_timeout($this->handle, $arg1, $arg2);

            case STREAM_OPTION_READ_BUFFER:
                if ($arg1 === STREAM_BUFFER_NONE) {
                    return stream_set_read_buffer($this->handle, 0) === 0;
                }

                return stream_set_read_buffer($this->handle, $arg2) === 0;

            case STREAM_OPTION_WRITE_BUFFER:
                $this->streamWriteBuffer = $arg1 === STREAM_BUFFER_NONE ? 0 : $arg2;

                return true;
        }

        return false;
    }
640410
public function uncheckOption($option)
    {
        $option = $this->fixStepArgument($option);
        $this->getSession()->getPage()->uncheckField($option);
    }
1320651
public function setOptions($options)
    {
        if (array_key_exists('allowipv6', $options)) {
            $this->_options['allowipv6'] = (boolean) $options['allowipv6'];
        }

        if (array_key_exists('allowipv4', $options)) {
            $this->_options['allowipv4'] = (boolean) $options['allowipv4'];
        }

        if (!$this->_options['allowipv4'] && !$this->_options['allowipv6']) {
            require_once 'Zend/Validate/Exception.php';
            throw new Zend_Validate_Exception('Nothing to validate. Check your options');
        }

        return $this;
    }
1355519
public function setOptions($options)
    {
        // Valid Options
        $validOptions = ['delete', 'update', 'constraint'];
        foreach ($options as $option => $value) {
            if (!in_array($option, $validOptions, true)) {
                throw new \RuntimeException(sprintf('"%s" is not a valid foreign key option.', $option));
            }

            // handle $options['delete'] as $options['update']
            if ('delete' === $option) {
                $this->setOnDelete($value);
            } elseif ('update' === $option) {
                $this->setOnUpdate($value);
            } else {
                $method = 'set' . ucfirst($option);
                $this->$method($value);
            }
        }

        return $this;
    }
490784
public function setOptions(array $options)
    {
        $this->validateOptions($options, $this->type);

        $this->options = $options;

        return $this;
    }
702099
public static function setOptionalValue( Option &$option, $arg )
    {
        if ( !self::isShortCode( $arg ) && !self::isLongCode( $arg ) )
        {
            if ( is_bool( $arg ) )
            {
                $option->value = ( bool )$arg;
            }
            elseif ( is_string( $arg ) )
            {
                $arg = trim( $arg );
            
                $option->value = $arg;
            }
        }
    }
128005
public function select($columns, $option = null)
    {
        $this
            ->getQueryBuilder()
            ->select($columns, $option);

        return $this;
    }
912320
public function setAlias($aliases, $option)
	{
		$aliases = (array) $aliases;

		foreach ($aliases as $alias)
		{
			$this->aliases[$alias] = $option;
		}

		return $this;
	}
1048920
public function assertSelectOptionNotFound($field, $option)
    {
        \PHPUnit_Framework_Assert::assertFalse(
            in_array($option, $this->findSelectOptions($field), true),
            sprintf('The select option "%s" from the select "%s" exists.', $option, $field)
        );
    }
1302630
private function assertOptionName(string $option): void
	{
		static $validOptions = [
			'delimiter',
			'validChars',
			'ignoreChars',
			'locale',
			'transforms',
			'preTransforms',
			'postTransforms',
		];

		if (!in_array($option, $validOptions, true)) {
			throw new \InvalidArgumentException(sprintf('Unknown option "%s"', $option));
		}
	}
1204346
public function unsetOption($option)
    {
        if (!isset(static::$availableOptions[$option])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid option specified: "%s". Expected one of (%s)',
                $option,
                implode(', ', array_keys(static::$availableOptions))
            ));
        }
        $pos = array_search(static::$availableOptions[$option], $this->options, true);
        if (false !== $pos) {
            unset($this->options[$pos]);
        }
    }
613610
private static function checkOptions($options)
    {
        if (!isset($options['retries']) || !is_int($options['retries']) || $options['retries'] <= 0) {
            throw new \InvalidArgumentException(
                'retry: the options.retries must be an integer with a positive value'
            );
        }
        if (!isset($options['interval']) || !is_float($options['interval']) || $options['interval'] <= 0.0) {
            throw new \InvalidArgumentException(
                'retry: the options.interval must be a float with a positive value'
            );
        }
    }
47768
protected function isValidOption(?string $option): bool
    {
        return in_array($option, $this->getOptions(), true) === true
            || ($this->isRequired() === false && $option === null);
    }
591511
public static function fromOption($option)
    {
        $message = sprintf(
            'Could not add invalid Option of type "%1$s" to option repository.',
            is_object($option)
                ? get_class($option)
                : gettype($option)
        );

        return new static($message);
    }