Return "declare()" and "use" statement code

@return Stmt[]
776405
private function getPhpFileStmt(\ReflectionClass $class) : array
    {
        $traverser = new NodeTraverser();
        $visitor = new CodeGenVisitor();
        $traverser->addVisitor($visitor);
        $fileName = $class->getFileName();
        if (is_bool($fileName)) {
            throw new InvalidSourceClassException(get_class($class));
        }
        $file = file_get_contents($fileName);
        if ($file === false) {
            throw new \RuntimeException($fileName); // @codeCoverageIgnore
        }
        $stmts = $this->parser->parse($file);
        if (is_array($stmts)) {
            $traverser->traverse($stmts);
        }

        return $visitor();
    }
657538
public function getImports()
    {
        $imports = [];
        $tokens = token_get_all(file_get_contents($this->file));
        reset($tokens);
        $token = '';
        while ($token !== false) {
            $token = next($tokens);
            if (!is_array($token)) {
                continue;
            }
            if ($token[0] === T_USE) {
                $stmt = $this->parseUseStatement($tokens);
                $imports += $stmt;
            } elseif ($token[0] === T_CLASS) {
                break;
            }
        }
        return $imports;
    }
133033
public function getFunctions()
    {
        $stmts = [];
        $stmts['drop/function/slugify'] = 'DROP FUNCTION IF EXISTS `slugify`';
        $stmts['create/function/slugify'] = <<< ENDQ
        CREATE FUNCTION `slugify` (dirty_string VARCHAR(255))
        RETURNS VARCHAR(255) CHARSET latin1
        DETERMINISTIC
        BEGIN
            DECLARE x, y , z INT;
            DECLARE temp_string, new_string VARCHAR(255);
            DECLARE is_allowed BOOL;
            DECLARE c, check_char VARCHAR(1);

            SET temp_string = LOWER(dirty_string);

            SET temp_string = REPLACE(temp_string, '&', ' and ');

            SELECT temp_string REGEXP('[^a-z0-9\-]+') INTO x;
            IF x = 1 THEN
                SET z = 1;
                WHILE z <= CHAR_LENGTH(temp_string) DO
                    SET c = SUBSTRING(temp_string, z, 1);
                    SET is_allowed = FALSE;
                    IF !((ascii(c) = 45) or (ascii(c) >= 48 and ascii(c) <= 57) or (ascii(c) >= 97 and ascii(c) <= 122)) THEN
                        SET temp_string = REPLACE(temp_string, c, '-');
                    END IF;
                    SET z = z + 1;
                END WHILE;
            END IF;

            SELECT temp_string REGEXP("^-|-$|'") INTO x;
            IF x = 1 THEN
                SET temp_string = REPLACE(temp_string, "'", '');
                SET z = CHAR_LENGTH(temp_string);
                SET y = CHAR_LENGTH(temp_string);
                Dash_check: WHILE z > 1 DO
                    IF STRCMP(SUBSTRING(temp_string, -1, 1), '-') = 0 THEN
                        SET temp_string = SUBSTRING(temp_string,1, y-1);
                        SET y = y - 1;
                    ELSE
                        LEAVE Dash_check;
                    END IF;
                    SET z = z - 1;
                END WHILE;
            END IF;

            REPEAT
                SELECT temp_string REGEXP("--") INTO x;
                IF x = 1 THEN
                    SET temp_string = REPLACE(temp_string, "--", "-");
                END IF;
            UNTIL x <> 1 END REPEAT;

            IF LOCATE('-', temp_string) = 1 THEN
                SET temp_string = SUBSTRING(temp_string, 2);
            END IF;

            RETURN temp_string;
        END        
ENDQ;

        $stmts['drop/function/strip_tags'] = 'DROP FUNCTION IF EXISTS `strip_tags`';
        $stmts['create/function/strip_tags'] = <<< 'ENDQ'
        CREATE FUNCTION strip_tags( DIRTY VARCHAR(3000) )
        RETURNS VARCHAR(3000) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci
        DETERMINISTIC 
        BEGIN
          DECLARE iStart, iEnd, iLength int;
            WHILE LOCATE( '<', DIRTY ) > 0 And LOCATE( '>', DIRTY, LOCATE( '<', DIRTY )) > 0 DO
              BEGIN
                SET iStart = LOCATE( '<', DIRTY ), iEnd = LOCATE( '>', DIRTY, LOCATE('<', DIRTY ));
                SET iLength = ( iEnd - iStart) + 1;
                IF iLength > 0 THEN
                  BEGIN
                    SET DIRTY = INSERT( DIRTY, iStart, iLength, '');
                  END;
                END IF;
              END;
            END WHILE;
            RETURN DIRTY;
        END;
ENDQ;

        $stmts['drop/function/delete_double_spaces'] = 'DROP FUNCTION IF EXISTS `delete_double_spaces`';
        $stmts['create/function/delete_double_spaces'] = <<< 'ENDQ'
        CREATE FUNCTION delete_double_spaces ( title VARCHAR(3000) )
        RETURNS VARCHAR(3000) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci 
        DETERMINISTIC
        BEGIN
            DECLARE result VARCHAR(3000);
            SET result = REPLACE( title, '  ', ' ' );
            WHILE (result <> title) DO 
                SET title = result;
                SET result = REPLACE( title, '  ', ' ' );
            END WHILE;
            RETURN result;
        END;
ENDQ;

        $stmts['drop/function/get_searchable_reference'] = 'DROP FUNCTION IF EXISTS `get_searchable_reference`';
        $stmts['create/function/get_searchable_reference'] = <<< 'ENDQ'
        CREATE FUNCTION `get_searchable_reference` (`in_str` VARCHAR(2048)) 
        RETURNS VARCHAR(2048) CHARSET utf8mb4
        DETERMINISTIC        
        BEGIN
            /*
              This function escape a string from any non alphanumeric chars (A_Z0_9)
              to get a searchable reference. Also try to remove any first 
              non-significative zero.

              FOR example 'BA-0114-22' -> 'BA11422'  

            */    
            DECLARE out_str VARCHAR(2048) DEFAULT '';
            DECLARE c VARCHAR(1) DEFAULT '';
            DECLARE prev_c VARCHAR(1) DEFAULT '';
            DECLARE pointer INT DEFAULT 1;

            IF ISNULL(in_str) THEN
                RETURN NULL;
            ELSE
                WHILE pointer <= LENGTH(in_str) DO
                    SET c = UPPER(MID(in_str, pointer, 1));

                    -- TAKE ONLY [A-Z0-9] characters
                    IF  ((ASCII(c) > 64 AND ASCII(c) < 92) or (ASCII(c) > 47 AND ASCII(c) < 58))
                    THEN
                        -- IF A NUMBER, try to get rid of non-significave numbers
                        IF (ASCII(c) > 47 AND ASCII(c) < 58)
                        THEN 
                            -- IF C is a zero and PREVIOUS CHARACTER IS NUMERIC
                            IF (c = 0 and NOT (ASCII(prev_c) > 47 AND ASCII(prev_c) < 58))
                            THEN
                                -- NOTHING
                                SET c = c;
                            ELSE
                                SET out_str = CONCAT(out_str, c);
                            END IF;
                        ELSE 
                            SET out_str = CONCAT(out_str, c);
                        END IF;
                    END IF;
                    SET prev_c = c;
                    SET pointer = pointer + 1;
                END WHILE;
            END IF;

            RETURN UPPER(out_str);
        END;
ENDQ;

        return $stmts;
    }
386047
protected function getDefaultCommands()
    {
        $commands = parent::getDefaultCommands();
        $commands[] = new Command\UseSortCommand();
        $commands[] = new Command\HeaderCommand();
        $commands[] = new Command\StrictCommand();

        return $commands;
    }
779679
public static function getRegisteredWrappers()
    {
        if (static::$wrapperRegistry === null) {
            static::$wrapperRegistry = [];

            if (extension_loaded('intl')) {
                static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\Intl';
            }

            if (extension_loaded('mbstring')) {
                static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\MbString';
            }

            if (extension_loaded('iconv')) {
                static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\Iconv';
            }

            static::$wrapperRegistry[] = 'Zend\Stdlib\StringWrapper\Native';
        }

        return static::$wrapperRegistry;
    }
120909
public function create(string $code): array
    {
        $stmt = $this->parser->parse($code);
        return $this->traverser->traverse($stmt);
    }
167661
protected function getUseClauseVariables()
    {
        $begin = strpos($code = $this->getCode(), '(', $this->getUseIndex()) + 1;

        return explode(',', substr($code, $begin, strpos($code, ')', $begin) - $begin));
    }
233750
public function getCodeLines() {
    // Add a terminal ';' to the last of the fluent method calls.
    $this->lines[count($this->lines) - 1] .= ';';

    $this->lines = $this->indentCodeLines($this->lines);

    return $this->lines;
  }
977913
public function getValuesWithModifiers()
    {
        $values = array_map(function ($value) {
            return [$value];
        }, array_flip($this->getValues()));

        $valuesWithModifiers = $values + $this->getModifiers(); // merge and keep keys (append)

        ksort($valuesWithModifiers);

        return $valuesWithModifiers;
    }
6150
function limitArray()
    {
        $limitValues = $this->attribute( 'values' );

        $valueArray = array();

        foreach ( array_keys( $limitValues ) as $valueKey )
        {
            $valueArray[] = $limitValues[$valueKey]->attribute( 'value' );
        }

        return array( $this->attribute( 'identifier' ) => $valueArray );
    }
1181360
protected function getSignalList(): array
    {
        if (null !== self::$list) {
            return self::$list;
        }

        $signals = [
            SIGHUP,
            SIGINT,
            SIGQUIT,
            SIGILL,
            SIGABRT,
            SIGTRAP,
            SIGBUS,
            SIGTERM,
            SIGSEGV,
            SIGFPE,
            SIGALRM,
            SIGVTALRM,
            SIGPROF,
            SIGIO,
            SIGCONT,
            SIGURG,
            SIGPIPE,
            SIGXCPU,
            SIGXFSZ,
            SIGTTIN,
            SIGTTOU,
            SIGUSR1,
            SIGUSR2,
        ];

        if (defined('SIGIOT')) {
            $signals[] = SIGIOT;
        }

        if (defined('SIGSTKFLT')) {
            $signals[] = SIGSTKFLT;
        }

        if (defined('SIGCLD')) {
            $signals[] = SIGCLD;
        }

        if (defined('SIGCHLD')) {
            $signals[] = SIGCHLD;
        }

        return self::$list = $signals;
    }
202279
public static function getKeywords()
    {
        static $keywords = null;

        if ($keywords === null) {
            $keywords = [];

            $keywordsStrings = [
                'T_ABSTRACT', 'T_ARRAY', 'T_AS', 'T_BREAK', 'T_CALLABLE', 'T_CASE',
                'T_CATCH', 'T_CLASS', 'T_CLONE', 'T_CONST', 'T_CONTINUE', 'T_DECLARE', 'T_DEFAULT', 'T_DO',
                'T_ECHO', 'T_ELSE', 'T_ELSEIF', 'T_EMPTY', 'T_ENDDECLARE', 'T_ENDFOR', 'T_ENDFOREACH',
                'T_ENDIF', 'T_ENDSWITCH', 'T_ENDWHILE', 'T_EVAL', 'T_EXIT', 'T_EXTENDS', 'T_FINAL',
                'T_FINALLY', 'T_FOR', 'T_FOREACH', 'T_FUNCTION', 'T_GLOBAL', 'T_GOTO', 'T_HALT_COMPILER',
                'T_IF', 'T_IMPLEMENTS', 'T_INCLUDE', 'T_INCLUDE_ONCE', 'T_INSTANCEOF', 'T_INSTEADOF',
                'T_INTERFACE', 'T_ISSET', 'T_LIST', 'T_LOGICAL_AND', 'T_LOGICAL_OR', 'T_LOGICAL_XOR',
                'T_NAMESPACE', 'T_NEW', 'T_PRINT', 'T_PRIVATE', 'T_PROTECTED', 'T_PUBLIC', 'T_REQUIRE',
                'T_REQUIRE_ONCE', 'T_RETURN', 'T_STATIC', 'T_SWITCH', 'T_THROW', 'T_TRAIT', 'T_TRY',
                'T_UNSET', 'T_USE', 'T_VAR', 'T_WHILE', 'T_YIELD',
            ];

            foreach ($keywordsStrings as $keywordName) {
                if (defined($keywordName)) {
                    $keyword = constant($keywordName);
                    $keywords[$keyword] = $keyword;
                }
            }
        }

        return $keywords;
    }
1221480
private function getUsesDeclarations()
    {
        asort( $this->usesDeclarations );
        $output = [];
        foreach( $this->usesDeclarations as $namespace ) {
            $output[] = sprintf( 'use %s;', $namespace );
        }
        return new Format( $output );
    }
791580
public function getVarDeclarations()
	{
		asort($this->jsLengths);

		$src = '';
		foreach (array_keys($this->jsLengths) as $varName)
		{
			$configValue = $this->configValues[$varName];
			if ($configValue->isDeduplicated())
			{
				$src .= '/** @const */ var ' . $varName . '=' . $this->encoder->encode($configValue->getValue()) . ";\n";
			}
		}

		return $src;
	}
573723
public static function create(): array
    {
        $tools = [];
        $config = Config::getInstance();
        foreach (self::VALID_TOOLS as $tool) {
            // SyntaxError is a special tool. Pahout directly generates Hint without checking AST.
            if ($tool !== 'SyntaxError') {
                $klass = "Pahout\\Tool\\".$tool;
                $tools[] = new $klass();
            }
        }

        return array_filter($tools, function ($tool) use ($config) {
            // Activate only tools that are not included in ignore_tools, and whose PHP version is applicable.
            return !in_array($tool::HINT_TYPE, $config->ignore_tools)
                     && version_compare($config->php_version, $tool::PHP_VERSION, '>=');
        });
    }
281427
private function getDataTypesDeclaration()
    {

        $arrayDeclaration = [];
        foreach( $this->entity->dataTypes as $name => $dataType ) {
            $arrayDeclaration[] = sprintf(
                "'%s' => %s,",
                $name,
                Php::varExport( $dataType->serialize() )
            );
        }

        $this->class->classComponents[] = new VariableDeclaration(
            'dataTypes',
            new SFormatf( <<<'PHP'
                /**
                 * Datatype information used by this entity. See, Bond\Entity\DataType
                 * @var array
                 */
                protected $dataTypes = [
%s
                ];
PHP
                , (new Format($arrayDeclaration))->indent(20)
            )
        );

    }
621895
public function getMatchers(): array
    {
        return [
            'verifyNative' => function (DataType $subject, $value) {

                $isClass = (false === $subject->isClass());
                $isClassOrInterface = (false === $subject->isClassOrInterface() || $value === Type::COUNTABLE);
                $isInterface = (false === $subject->isInterface() || $value === Type::COUNTABLE);
                $isNative = (true === $subject->isNative());
                $isTrait = (false === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (false === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));


                return $isClass && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            },
            'verifyInterface' => function (DataType $subject, $value) {

                $isClass = (false === $subject->isClass());
                $isClassOrInterface = (true === $subject->isClassOrInterface());
                $isInterface = (true === $subject->isInterface());
                $isNative = (false === $subject->isNative());
                $isTrait = (false === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (false === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));


                return $isClass && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            },
            'verifyClass' => function (DataType $subject, $value) {

                $isClass = (true === $subject->isClass());
                $isClassOrInterface = (true === $subject->isClassOrInterface());
                $isInterface = (false === $subject->isInterface());
                $isNative = (false === $subject->isNative());
                $isTrait = (false === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (true === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));

                return $isClass && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            },
            'verifyTrait' => function (DataType $subject, $value) {

                $isClass = (false === $subject->isClass());
                $isClassOrInterface = (false === $subject->isClassOrInterface());
                $isInterface = (false === $subject->isInterface());
                $isNative = (false === $subject->isNative());
                $isTrait = (true === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (false === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));

                return $isClass  && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            }
        ];
    }