Validate a class definition statement.

@param Class_ $stmt
199149
protected function validateClassStatement(Class_ $stmt)
    {
        $this->ensureCanDefine($stmt, self::CLASS_TYPE);
        if (isset($stmt->extends)) {
            $this->ensureClassExists($this->getFullyQualifiedName($stmt->extends), $stmt);
        }
        $this->ensureInterfacesExist($stmt->implements, $stmt);
    }
1313425
public static boolean validate(Statement stmt) {
    try {
      Connection conn = stmt.getConnection();
      if (conn == null)
        return false;

      if (!conn.isClosed() && conn.isValid(10))
        return true;

      stmt.close();
      conn.close();
    } catch (SQLException e) {
      // this may well fail. that doesn't matter. we're just making an
      // attempt to clean up, and if we can't, that's just too bad.
    }
    return false;
  }
1068925
protected function _process( array $stmts )
	{
		$this->_msg( 'Changing attribute value type in order domain', 0 );
		$this->_status( '' );

		foreach( $stmts as $table => $stmts )
		{
			$this->_msg( sprintf( 'Checking table "%1$s": ', $table ), 1 );

			if( $this->_schema->tableExists( $table ) === true &&
				$this->_schema->columnExists( $table, 'value' ) === true &&
				$this->_schema->getColumnDetails( $table, 'value' )->getDataType() === 'varchar'
			) {
				foreach( $stmts['index'] as $index => $sql )
				{
					if( $this->_schema->indexExists( $table, $index ) === true ) {
						$this->_execute( $sql );
					}
				}

				$this->_execute( $stmts['column'] );
				$this->_status( 'changed' );
			}
			else
			{
				$this->_status( 'OK' );
			}
		}
	}
441647
protected function _process( array $stmts )
	{
		$table = 'mshop_plugin';
		$constraint = 'fk_msplu_typeid';

		$this->_msg( 'Adding constraint for table mshop_plugin', 0 ); $this->_status( '' );

		$this->_msg( sprintf( 'Checking constraint "%1$s": ', $constraint ), 1 );

		if( $this->_schema->tableExists( $table ) === true
			&& $this->_schema->columnExists( $table, 'typeid' )
			&& $this->_schema->constraintExists( $table, $constraint ) === false )
		{
			$this->_execute( $stmts[ $constraint ] );
			$this->_status( 'added' );
		}
		else
		{
			$this->_status( 'OK' );
		}
	}
74909
protected function _process( array $stmts )
	{
		$this->_msg( 'Remove listflag from mshop_product table', 0 ); $this->_status( '' );

		$table = 'mshop_product';

		if( $this->_schema->tableExists( $table ) === true )
		{
			foreach( $stmts['column'] as $column => $stmt)
			{
				$this->_msg( sprintf( 'Checking column "%1$s": ', $column ), 1 );

				if( $this->_schema->columnExists( $table, $column ) === true )
				{
					$this->_execute( $stmt );
					$this->_status( 'removed' );
				}
				else {
					$this->_status( 'OK' );
				}
			}

			foreach( $stmts['index'] as $index => $stmt)
			{
				$this->_msg( sprintf( 'Checking index "%1$s": ', $index ), 1 );

				if( $this->_schema->indexExists( $table, $index ) === true)
				{
					$this->_execute( $stmt );
					$this->_status( 'removed' );
				} else {
					$this->_status( 'OK' );
				}
			}
		}
	}
222687
private function checkMethod($method_id, PhpParser\Node $stmt, Codebase $codebase)
    {
        $class = explode('::', $method_id)[0];

        if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
            $this,
            $class,
            new CodeLocation($this, $stmt),
            [],
            true
        ) === false
        ) {
            return false;
        }

        $this_context = new Context();
        $this_context->self = $class;
        $this_context->vars_in_scope['$this'] = new Type\Union([new Type\Atomic\TNamedObject($class)]);

        $constructor_id = $class . '::__construct';

        $this->project_analyzer->getMethodMutations(
            $constructor_id,
            $this_context,
            $this->getRootFilePath(),
            $this->getRootFileName()
        );

        $this_context->vars_in_scope['$this'] = new Type\Union([new Type\Atomic\TNamedObject($class)]);

        // check the actual method
        $this->project_analyzer->getMethodMutations(
            $method_id,
            $this_context,
            $this->getRootFilePath(),
            $this->getRootFileName()
        );

        $view_context = new Context();
        $view_context->self = self::VIEW_CLASS;

        // add all $this-> vars to scope
        foreach ($this_context->vars_possibly_in_scope as $var => $_) {
            $view_context->vars_in_scope[str_replace('$this->', '$', $var)] = Type::getMixed();
        }

        foreach ($this_context->vars_in_scope as $var => $type) {
            $view_context->vars_in_scope[str_replace('$this->', '$', $var)] = $type;
        }

        return $view_context;
    }
808800
protected function _process( $stmt )
	{
		$table = 'madmin_log';

		$this->_msg( 'Changing site ID to NULL in madmin_log', 0 );
		$this->_status('');

		$this->_msg(sprintf('Changing table "%1$s": ', $table), 1);

		if( $this->_schema->tableExists($table) &&
			!$this->_schema->getColumnDetails( $table, 'siteid' )->isNullable() )
		{
			$this->_execute( $stmt );
			$this->_status( 'done' );
		} else {
			$this->_status( 'OK' );
		}

	}
1126171
protected function doValidate()
    {
        // Scan all directories mentioned and validate the class map against the entries.
        foreach ($this->information as $path) {
            $subPath  = $this->prependPathWithBaseDir($path);
            $classMap = $this->classMapFromPath($subPath);

            if (empty($classMap)) {
                $this->report->error(new NoClassesFoundInPathViolation($this->getName(), $path));
            }
        }
    }
791307
private function isValidClass(PhpClass $class)
    {
        $classNames = $this->config->get('classNames');
        return (empty($classNames) || in_array(
            $class->getIdentifier(),
            $classNames
        ));
    }
1247220
private function bind($stmt) {

		$meta 	= $stmt -> result_metadata();
		$double = [];
		$vars 	= [];

		if($stmt -> field_count > 0) {

			while($field = $meta -> fetch_field()) {

				$columnname  = $field -> name;
				${$columnname} = null;
				
				if(true === array_key_exists($columnname, $vars)) {
					$double[] = $columnname;
				}
				else {
					$vars[$columnname] = &${$columnname};
				}
			}
		}

		if(count($double) > 0) {
			return trigger_error(sprintf('Column %s in field list is ambiguous', implode(', ', array_unique($double))));
		}

		call_user_func_array([$stmt, 'bind_result'], $vars);

		return $vars;
	}
973706
public function validateModelClass()
    {
        if ($this->isReservedKeyword($this->modelClass)) {
            $this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
        }
        if ((empty($this->tableName) || substr_compare($this->tableName, '*', -1, 1)) && $this->modelClass == '') {
            $this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
        }
    }
1279235
public function collectAnalyzableClassLike(PhpParser\Node\Stmt\ClassLike $stmt)
    {
        if (!$stmt->name) {
            throw new \UnexpectedValueException('Did not expect anonymous class here');
        }

        $fq_class_name = Type::getFQCLNFromString($stmt->name->name, $this->getAliases());

        if ($stmt instanceof PhpParser\Node\Stmt\Class_) {
            $this->source->addNamespacedClassAnalyzer(
                $fq_class_name,
                new ClassAnalyzer($stmt, $this, $fq_class_name)
            );
        } elseif ($stmt instanceof PhpParser\Node\Stmt\Interface_) {
            $this->source->addNamespacedInterfaceAnalyzer(
                $fq_class_name,
                new InterfaceAnalyzer($stmt, $this, $fq_class_name)
            );
        }
    }
1027075
protected function _process( array $stmts )
	{
		$this->_msg( 'Changing list ids to NOT NULL', 0 );
		$this->_status('');
		
		foreach( $stmts as $tablename => $stmt )
		{
			$this->_msg(sprintf('Checking table "%1$s": ', $tablename), 1);
			
			if( $this->_schema->tableExists( $tablename ) === true
				&& $this->_schema->getColumnDetails( $tablename, 'id' )->isNullable() === true )
			{
				$this->_execute( $stmt );
				$this->_status( 'migrated' );
			}
			else
			{
				$this->_status( 'OK' );
			}
		}
	}
1066596
public function pStmt_If(Stmt\If_ $node)
    {
        return sprintf(
            "%s (%s) %s%s\n%s%s%s",
            $this->color('if', SyntaxHighlighterConfig::TYPE_KEYWORD),
            $this->p($node->cond),
            $this->color('{', SyntaxHighlighterConfig::TYPE_BRACE),
            $this->pStmts($node->stmts),
            $this->color('}', SyntaxHighlighterConfig::TYPE_BRACE),
            $this->pImplode($node->elseifs),
            (null !== $node->else ? $this->p($node->else) : '')
        );
    }
464156
public function read(\PDOStatement $stmt)
    {

        $this->unfoundPrecedence=array();

        $preparedReader = new PreparedOperations($this->FQuery);


        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            // loop over joined faces
            foreach ($preparedReader->getPreparedFaces() as $basePath => $preparedFace) {

                $identity = $preparedFace->rowIdentity($row, $basePath);

                if ($identity) {
                    // if already instantiated then get it from ikeeper and try the forwards
                    if ($this->instancesKeeper->hasInstance($preparedFace->getFace()->getClass(), $identity)) {
                        $instance = $this->instancesKeeper->getInstance($preparedFace->getFace()->getClass(), $identity);

                        $preparedFace->runOperations($instance,$row,$this->instancesKeeper, $this->unfoundPrecedence);

                        if (!$this->resultSet->pathHasIdentity($basePath, $identity)) {
                            $this->resultSet->addInstanceByPath($basePath, $instance, $identity);
                        }

                        // else create the instance and hydrate it
                    } else {
                        $instance = $this->createInstance($preparedFace->getFace());
                        $this->instancesKeeper->addInstance($instance, $identity);
                        $this->resultSet->addInstanceByPath($basePath, $instance, $identity);

                        $preparedFace->runOperations($instance,$row,$this->instancesKeeper, $this->unfoundPrecedence);

                    }
                }

            }


        }

        // set unset instances. To be improved ?
        foreach ($this->unfoundPrecedence as $unfound) {

            if(!$this->instancesKeeper->hasInstance($unfound['elementToSet']->getClass(), $unfound['identityOfElement'])){

                var_dump($unfound['elementToSet']->getClass());
                var_dump($unfound['identityOfElement']);
                var_dump(get_class($instance));

            }

            $unfoundInstance = $this->instancesKeeper->getInstance($unfound['elementToSet']->getClass(), $unfound['identityOfElement']);
            $unfound['instance']->faceSetter($unfound['elementToSet'], $unfoundInstance);
        }


        return $this->resultSet;

    }
441596
protected function getResultsStrictTyped(\PDOStatement $stmt, int $fetchStyle = \PDO::FETCH_ASSOC)
    {
        /**
         * @var array|object|bool $results
         */
        $results = $stmt->fetchAll($fetchStyle);
        if (\is_array($results)) {
            return $results;
        } elseif (\is_object($results)) {
            return $results;
        }
        throw new \TypeError('Unexpected return type: ' . $this->getValueType($results));
    }
1185986
protected function process( array $stmts )
	{
		$this->msg( 'Removing locale constraints from customer tables', 0 );
		$this->status( '' );

		$schema = $this->getSchema( 'db-customer' );

		foreach( $stmts as $table => $list )
		{
			if( $schema->tableExists( $table ) === true )
			{
				foreach( $list as $constraint => $stmt )
				{
					$this->msg( sprintf( 'Removing "%1$s" from "%2$s"', $constraint, $table ), 1 );

					if( $schema->constraintExists( $table, $constraint ) !== false )
					{
						$this->execute( $stmt, 'db-customer' );
						$this->status( 'done' );
					} else {
						$this->status( 'OK' );
					}
				}
			}
		}
	}