Run Php through lint checker
@retrun bool Is the passed php valid
489959
public function isValid( &$errors = null, $throwException = false )
    {

        // open pipe
        $descriptorSpec = array(
            0 => array('pipe', 'r'),
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w'),
        );

        $process = proc_open('php -l', $descriptorSpec, $pipes);

        if (!is_resource($process)) {
            throw new \Exception('Could not open PHP');
        }
        fwrite($pipes[0], $this->php);
        fclose($pipes[0]);

        $errors = stream_get_contents($pipes[2]);
        fclose($pipes[2]);

        $returnValue = proc_close($process);

        if( $throwException && $returnValue !== 0 ) {
            throw new BadPhpException($errors);
        }

        return $returnValue === 0;

    }
21659
static function validateInputHandlers( &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
    {
        $result = array( 'validated' => true, 'warnings' => array() );
        $validated =& $result['validated'];
        $warnings =& $result['warnings'];

        $http = eZHTTPTool::instance();

        $functionName = 'validateInput';
        $params = array( $http,
                         &$module,
                         &$class,
                         $object,
                         &$version,
                         $contentObjectAttributes,
                         $editVersion,
                         $editLanguage,
                         $fromLanguage,
                         $validationParameters );

        $validationResults = self::executeHandlerFunction( $functionName, $params );

        foreach( $validationResults as $validationResult )
        {
            $value = $validationResult['function']['value'];

            if ( $value['is_valid'] == false )
            {
                if ( $value['warnings'] )
                    $warnings = array_merge( $warnings, $value['warnings'] );

                $validated = false;
            }
        }

        return $result;
    }
828087
protected function validate_version_php() {

        if (!isset($this->assertions['plugintype'])) {
            throw new coding_exception('Required plugin type must be set before calling this');
        }

        if (!isset($this->assertions['moodleversion'])) {
            throw new coding_exception('Required Moodle version must be set before calling this');
        }

        $fullpath = $this->extractdir.'/'.$this->rootdir.'/version.php';

        if (!file_exists($fullpath)) {
            // This is tolerated for themes only.
            if ($this->assertions['plugintype'] === 'theme') {
                $this->add_message(self::DEBUG, 'missingversionphp');
                return true;
            } else {
                $this->add_message(self::ERROR, 'missingversionphp');
                return false;
            }
        }

        $this->versionphp = array();
        $info = $this->parse_version_php($fullpath);

        if (isset($info['module->version'])) {
            $this->add_message(self::ERROR, 'versionphpsyntax', '$module');
            return false;
        }

        if (isset($info['plugin->version'])) {
            $this->versionphp['version'] = $info['plugin->version'];
            $this->add_message(self::INFO, 'pluginversion', $this->versionphp['version']);
        } else {
            $this->add_message(self::ERROR, 'missingversion');
            return false;
        }

        if (isset($info['plugin->requires'])) {
            $this->versionphp['requires'] = $info['plugin->requires'];
            if ($this->versionphp['requires'] > $this->assertions['moodleversion']) {
                $this->add_message(self::ERROR, 'requiresmoodle', $this->versionphp['requires']);
                return false;
            }
            $this->add_message(self::INFO, 'requiresmoodle', $this->versionphp['requires']);
        }

        if (!isset($info['plugin->component'])) {
            $this->add_message(self::ERROR, 'missingcomponent');
            return false;
        }

        $this->versionphp['component'] = $info['plugin->component'];
        list($reqtype, $reqname) = core_component::normalize_component($this->versionphp['component']);
        if ($reqtype !== $this->assertions['plugintype']) {
            $this->add_message(self::ERROR, 'componentmismatchtype', array(
                'expected' => $this->assertions['plugintype'],
                'found' => $reqtype));
            return false;
        }
        if ($reqname !== $this->rootdir) {
            $this->add_message(self::ERROR, 'componentmismatchname', $reqname);
            return false;
        }
        $this->add_message(self::INFO, 'componentmatch', $this->versionphp['component']);

        if (isset($info['plugin->maturity'])) {
            $this->versionphp['maturity'] = $info['plugin->maturity'];
            if ($this->versionphp['maturity'] === 'MATURITY_STABLE') {
                $this->add_message(self::INFO, 'maturity', $this->versionphp['maturity']);
            } else {
                $this->add_message(self::WARNING, 'maturity', $this->versionphp['maturity']);
            }
        }

        if (isset($info['plugin->release'])) {
            $this->versionphp['release'] = $info['plugin->release'];
            $this->add_message(self::INFO, 'release', $this->versionphp['release']);
        }

        return true;
    }
742702
function _validate_files(&$files) {
        global $CFG, $COURSE;

        $files = array();

        if (empty($_FILES)) {
            // we do not need to do any checks because no files were submitted
            // note: server side rules do not work for files - use custom verification in validate() instead
            return true;
        }

        $errors = array();
        $filenames = array();

        // now check that we really want each file
        foreach ($_FILES as $elname=>$file) {
            $required = $this->_form->isElementRequired($elname);

            if ($file['error'] == 4 and $file['size'] == 0) {
                if ($required) {
                    $errors[$elname] = get_string('required');
                }
                unset($_FILES[$elname]);
                continue;
            }

            if (!empty($file['error'])) {
                $errors[$elname] = file_get_upload_error($file['error']);
                unset($_FILES[$elname]);
                continue;
            }

            if (!is_uploaded_file($file['tmp_name'])) {
                // TODO: improve error message
                $errors[$elname] = get_string('error');
                unset($_FILES[$elname]);
                continue;
            }

            if (!$this->_form->elementExists($elname) or !$this->_form->getElementType($elname)=='file') {
                // hmm, this file was not requested
                unset($_FILES[$elname]);
                continue;
            }

            // NOTE: the viruses are scanned in file picker, no need to deal with them here.

            $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
            if ($filename === '') {
                // TODO: improve error message - wrong chars
                $errors[$elname] = get_string('error');
                unset($_FILES[$elname]);
                continue;
            }
            if (in_array($filename, $filenames)) {
                // TODO: improve error message - duplicate name
                $errors[$elname] = get_string('error');
                unset($_FILES[$elname]);
                continue;
            }
            $filenames[] = $filename;
            $_FILES[$elname]['name'] = $filename;

            $files[$elname] = $_FILES[$elname]['tmp_name'];
        }

        // return errors if found
        if (count($errors) == 0){
            return true;

        } else {
            $files = array();
            return $errors;
        }
    }
187636
function lint () {
  console.log(
    chalk.gray('Running linting…\n')
  )

  // Run all linters
  const results = [
    dockerLinter,
    templateLinter,
    javascriptLinter,
    markdownLinter,
    sassLinter
  ]
    .map((Linter) => {
      const linter = new Linter()
      return linter.lint()
    })

  console.log(
    chalk.gray('\nlinting complete!')
  )

  const erred = results.indexOf(true) !== -1

  // If file was called via CLI and there are errors exit process with failed status
  if (require.main === module && erred) {
    process.exit(1)
  }

  return erred
}
635895
public static function lintFile($filename)
    {
        if (!file_exists($filename)) {
            return false;
        }

        if (self::supported(self::SUPPORT_RUNKIT_SANDBOX)) {
            /** @noinspection PhpUndefinedFunctionInspection */
            return runkit_lint_file($filename);
        }

        $cmd = 'php -l ' . escapeshellcmd($filename) . ' 2>&1';

        exec($cmd, $output, $retcode);

        return 0 === $retcode;
    }
761857
public function check()
    {
        $returnValue = null;

        
        $validity = null;
        $name = $this->getName();
        if (($value = ini_get($name)) !== false){
            // The ini value exists for this name.
            if ((($value == '') ? '0' : $value) == $this->getExpectedValue()){
                $validity = common_configuration_Report::VALID;
                $message = "PHP Configuration Option '${name}' = '${value}' has an expected value.";
            }
            else {
                $validity = common_configuration_Report::INVALID;
                $message = "PHP Configuration Option '${name}' = '${value}' has an unexpected value.";
            }
        }
        else {
            // Unknown ini value name.
            $validity = common_configuration_Report::UNKNOWN;
            $message = "PHP Configuration Option '${name}' is unknown.";
        }

        $returnValue = new common_configuration_Report($validity, $message, $this);
        

        return $returnValue;
    }
659566
public function isValidRegex()
    {
        set_error_handler(function ($errno, $errstr) {
            throw new InvalidArgumentException($errstr, $errno);
        }, E_WARNING);

        $valid = true;

        try {
            preg_match($this->string, 'tester');
        } catch (InvalidArgumentException $e) {
            $valid = false;
        }

        restore_error_handler();

        return $valid;
    }
967633
public function validate()
    {
        $valid = true;
        $message = null;
        $type = $this->Type;

        // Check if empty strings
        switch ($type) {
            case 'URL':
            case 'Email':
            case 'Phone':
                if ($this->{$type} == '') {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_EMPTY'.strtoupper($type),
                        'You must enter a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
            case 'File':
            case 'SiteTree':
                if ($type && empty($this->{$type.'ID'})) {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_OBJECT',
                        'Please select a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
        }
        // if its already failed don't bother checking the rest
        if ($valid) {
            switch ($type) {
                case 'URL':
                    $allowedFirst = ['#', '/'];
                    if (!in_array(substr($this->URL, 0, 1), $allowedFirst) && !filter_var($this->URL, FILTER_VALIDATE_URL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDURL',
                            'Please enter a valid URL.  Be sure to include http:// for an external URL. or begin your internal url/anchor with a "/" character'
                        );
                    }
                    break;
                case 'Email':
                    if (!filter_var($this->Email, FILTER_VALIDATE_EMAIL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDEMAIL',
                            'Please enter a valid Email address'
                        );
                    }
                    break;
                case 'Phone':
                    if (!preg_match("/^\+?[0-9a-zA-Z\-\s]*[\,\#]?[0-9\-\s]*$/", $this->Phone)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDPHONE',
                            'Please enter a valid Phone number'
                        );
                    }
                    break;
            }
        }

        $result = ValidationResult::create();
        if (!$valid) {
            $result->addError($message);
        }

        $this->extend('updateValidate', $result);

        return $result;
    }
692690
private static function isCli()
    {
        if (self::$cli === null) {
            //initial setter
            if (php_sapi_name() == 'cli') {
                self::$cli = true;
            } else {
                self::$cli = false;
            }
        }

        return self::$cli;
    }
746369
public function validateGenerator() : \Generator {
		yield 80 => $this->generatorPrefix . __( 'Validating file', 'pressbooks' );

		// Xmllint params
		$command = PB_XMLLINT_COMMAND . ' --html --valid --noout ' . escapeshellcmd( $this->outputPath ) . ' 2>&1';

		// Execute command
		$output = [];
		$return_var = 0;
		exec( $command, $output, $return_var );

		// Is this a valid XHTML?
		if ( is_countable( $output ) && count( $output ) ) {
			$this->logError( implode( "\n", $output ) );
			throw new \Exception();
		}

		yield 100 => $this->generatorPrefix . __( 'Validation successful', 'pressbooks' );
	}
645686
public function validateInput(): bool
    {
        if (!$def = $this->definition) {
            return true;
        }

        $in        = $this->input;
        $out       = $this->output;
        $givenArgs = $errArgs = [];

        foreach ($in->getArgs() as $key => $value) {
            if (\is_int($key)) {
                $givenArgs[$key] = $value;
            } else {
                $errArgs[] = $key;
            }
        }

        if (\count($errArgs) > 0) {
            $out->liteError(\sprintf('Unknown arguments (error: "%s").', \implode(', ', $errArgs)));
            return false;
        }

        $defArgs     = $def->getArguments();
        $missingArgs = \array_filter(\array_keys($defArgs), function ($name, $key) use ($def, $givenArgs) {
            return !\array_key_exists($key, $givenArgs) && $def->argumentIsRequired($name);
        }, \ARRAY_FILTER_USE_BOTH);

        if (\count($missingArgs) > 0) {
            $out->liteError(\sprintf('Not enough arguments (missing: "%s").', \implode(', ', $missingArgs)));
            return false;
        }

        $index = 0;
        $args  = [];

        foreach ($defArgs as $name => $conf) {
            $args[$name] = $givenArgs[$index] ?? $conf['default'];
            $index++;
        }

        $in->setArgs($args);

        // check options
        $opts      = $missingOpts = [];
        $givenOpts = $in->getOptions();
        $defOpts   = $def->getOptions();

        // check unknown options
        if ($unknown = \array_diff_key($givenOpts, $defOpts)) {
            $names = \array_keys($unknown);
            $first = \array_shift($names);

            throw new \InvalidArgumentException(\sprintf(
                'Input option is not exists (unknown: "%s").',
                (isset($first[1]) ? '--' : '-') . $first
            ));
        }

        foreach ($defOpts as $name => $conf) {
            if (!$in->hasLOpt($name)) {
                if (($srt = $conf['shortcut']) && $in->hasSOpt($srt)) {
                    $opts[$name] = $in->sOpt($srt);
                } elseif ($conf['required']) {
                    $missingOpts[] = "--{$name}" . ($srt ? "|-{$srt}" : '');
                }
            }
        }

        if (\count($missingOpts) > 0) {
            $out->liteError(
                \sprintf('Not enough options parameters (missing: "%s").',
                    \implode(', ', $missingOpts))
            );
            return false;
        }

        if ($opts) {
            $in->setLOpts($opts);
        }

        return true;
    }
870566
private function validateInput()
    {
        $returnValue = (bool) false;

        
        
        $returnValue = true;
        
        /**
         * Parse the arguments from the command lines 
         * and set them into the parameter variable.
         * All the current formats are allowed:
         * <code>
         * php script.php -arg1 value1 -arg2 value2
         * php script.php --arg1 value1 --arg2 value2
         * php script.php -arg1=value1 -arg2=value2
         * php script.php --arg1=value1 --arg2=value2
         * php script.php value1 value2 //the key will be numeric
         * </code>
         */
        $i = 1;
        while($i < count($this->argv)){
        	$arg = trim($this->argv[$i]);
        	if(!empty($arg)){
        	    // command -(-)arg1=value1
        		if(preg_match("/^[\-]{1,2}\w+=(.*)+$/", $arg)){
        		    $sequence = explode('=', preg_replace("/^[\-]{1,}/", '', $arg));
	        		if(count($sequence) >= 2){
	        			$this->parameters[$sequence[0]] = $sequence[1];
	        		}
	        	}
	        	// command -(-)arg1 value1 value2
        		else if(preg_match("/^[\-]{1,2}\w+$/", $arg)){
        		    $key = preg_replace("/^[\-]{1,}/", '', $arg);
    			    $this->parameters[$key] = '';
    			    while(isset($this->argv[$i + 1]) && substr(trim($this->argv[$i + 1]),0,1)!='-') {
    			        $this->parameters[$key] .= trim($this->argv[++$i]).' ';
    			    }
    			    $this->parameters[$key] = substr($this->parameters[$key], 0, -1); 
	        	}
        	    // command value1 value2
	        	else{
	        		$this->parameters[$i] = $arg;
	        	}
        	}
        	$i++;
        }

        //replaces shortcuts by their original names
        if (isset($this->inputFormat['parameters'])) {
            foreach($this->inputFormat['parameters'] as $parameter){
            	if(isset($parameter['shortcut'])){
            		$short = $parameter['shortcut'];
            		$long = $parameter['name'];
            		if(array_key_exists($short, $this->parameters) && !array_key_exists($long, $this->parameters)){
    					$this->parameters[$long] = $this->parameters[$short];
    					unset($this->parameters[$short]);
    				}
            	}
            }
        }
        
        //one we have the parameters, we can validate it
        if(isset($this->inputFormat['min'])){
        	$min 	= (int) $this->inputFormat['min'];
        	$found 	=  count($this->parameters);
        	if($found < $min){
        		$this->err("Invalid parameter count: $found parameters found ($min expected)");
        		$returnValue = false;
        	}
        }
        
        if(isset($this->inputFormat['required']) && is_array($this->inputFormat['required']) && count($this->inputFormat['required'])){
        	
			$requireds = array();
			if(!is_array($this->inputFormat['required'][0])){
        		$requireds = array($this->inputFormat['required']);
        	}else{
        		$requireds = $this->inputFormat['required'];
        	}
        	
        	$found = false;
        	foreach($requireds as $required){
        		
        		$matched = 0;
	        	foreach($required as $parameter){
	        		if(array_key_exists($parameter, $this->parameters)){
	        			$matched++;
	        		}
	        	}
	        	if($matched == count($required)){
        			$found = true;
        			break;
	        	}
        	}
        	
        	if(!$found){
        		$this->err("Unable to find required arguments");
        		$returnValue = false;
        	}
        }
        
        if($returnValue && isset($this->inputFormat['parameters'])){
        	 foreach($this->inputFormat['parameters'] as $parameter){
        		if(isset($this->parameters[$parameter['name']])){
	        	 	$input = $this->parameters[$parameter['name']];
		        	switch($parameter['type']){
		        		case 'file': 
		       				if( !is_file($input) || 
		       					!file_exists($input) || 
		       					!is_readable($input))
		       				{
		       					$this->err("Unable to access to the file: $input");
		       					$returnValue = false;
		       				}
		       				break;
	        			case 'dir': 
	        				if( !is_dir($input) || 
	        					!is_readable($input))
	        				{
	        					$this->err("Unable to access to the directory: $input");
	        					$returnValue = false;
	        				}
	        				break;
	        			case 'path': 
	        				if( !is_dir(dirname($input)) )
	        				{
	        					$this->err("Wrong path given: $input");
	        					$returnValue = false;
	        				}
	        				break;
	        			case 'int':
	        			case 'float':
	        			case 'double':
	        				if(!is_numeric($input)){
	        					$this->err("$input is not a valid ".$parameter['type']);
	        					$returnValue = false;
	        				}
	        				break;
	        			case 'string':
	        				if(!is_string($input)){
	        					$this->err("$input is not a valid ".$parameter['type']);
	        					$returnValue = false;
	        				}
	        				break;
	        			case 'boolean':
	        				if(!is_bool($input) && strtolower($input) != 'true' && strtolower($input) != 'false' && !empty($input)){
	        					$this->err("$input is not a valid ".$parameter['type']);
	        					$returnValue = false;
	        				}else{
	        					if(is_bool($input)){
	        						$this->parameters[$parameter['name']] = $input = settype($input, 'boolean');
	        					}
	        					else if(!empty($input)){
	        						$this->parameters[$parameter['name']] = ((strtolower($input) == 'true') ? true : false);
	        					}
	        					else{
	        						$this->parameters[$parameter['name']] = true;
	        					}
	        				}
	        				break;
	        				
	        		}
        		}
        	}
        }
        
 
        
        

        return (bool) $returnValue;
    }
1189603
function lint() {
  var errorsFound = false;
  var stream = gulp.src(config.lintGlobs);

  if (isWatching) {
    stream = stream.pipe(watcher());
  }

  if (argv.fix) {
    options.fix = true;
  }

  return stream.pipe(eslint(options))
    .pipe(eslint.formatEach('stylish', function(msg) {
      errorsFound = true;
      util.log(util.colors.red(msg));
    }))
    .pipe(gulpIf(isFixed, gulp.dest('.')))
    .pipe(eslint.failAfterError())
    .on('end', function() {
      if (errorsFound && !options.fix) {
        util.log(util.colors.blue('Run `gulp lint --fix` to automatically ' +
            'fix some of these lint warnings/errors. This is a destructive ' +
            'operation (operates on the file system) so please make sure ' +
            'you commit before running.'));
      }
    });
}
82621
private function lintFile($file)
    {
        // first try to parse it
        try {
            $this->parser->parse(\file_get_contents($file));
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
56420
protected function _isValidFormat()
	{
		//	Reading 2048 bytes should be enough to validate that the format is HTML
		$data = fread($this->_fileHandle, 2048);
		if ((strpos($data, '<') !== FALSE) &&
			(strlen($data) !== strlen(strip_tags($data)))) {
			return TRUE;
		}

		return FALSE;
	}
502138
protected function isSyntacticallyValid(): bool
    {
        if (preg_match('!^([a-z][a-z0-9\+]*)://([^@]+@)?([^/?#]*)(/([^#?]*))?(.*)$!', $this->parsedUri->asString()) == 0) {
            return false;
        }

        if ($this->parsedUri->hasUser()) {
            if (preg_match('~([@:/])~', $this->parsedUri->user()) != 0) {
                return false;
            }

            if (!empty($this->parsedUri->password()) && preg_match('~([@:/])~', $this->parsedUri->password()) != 0) {
                return false;
            }
        }

        if (!$this->parsedUri->hasHostname() || strlen($this->parsedUri->hostname()) === 0) {
            return true;
        }

        if ($this->parsedUri->hasHostname()
          && preg_match('!^([a-zA-Z0-9\.-]+|\[[^\]]+\])(:([0-9]+))?$!', $this->parsedUri->hostname()) != 0) {
            return true;
        }

        return false;
    }