src/Mouf/CodeValidatorService.php
public static function validateCode($codeString) {
		$code = "<?php \$a = function(ContainerInterface \$container) { ".$codeString."\n}\n?>";
	
		$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
	
		$stmts = $parser->parse($code);

		// If we are here, the code is correct.
		// Let's add a last check: whether there is a "return" keyword or not.
		if (stripos($code, "return") === false) {
			throw new Error("Missing 'return' keyword.", count(explode("\n", $codeString)));
		}
	}
public static function validateCode($codeString) {
		$code = "<?php \$a = function(ContainerInterface \$container) { ".$codeString."\n}\n?>";
	
		$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
	
		$stmts = $parser->parse($code);

		// If we are here, the code is correct.
		// Let's add a last check: whether there is a "return" keyword or not.
		if (stripos($code, "return") === false) {
			throw new Error("Missing 'return' keyword.", count(explode("\n", $codeString)));
		}
	}
public static function validateCode ( $ codeString ) { $ code = "<?php \$a = function(ContainerInterface \$container) { " . $ codeString . "\n}\n?>" ; $ parser = ( new ParserFactory ( ) ) -> create ( ParserFactory :: PREFER_PHP7 ) ; $ stmts = $ parser -> parse ( $ code ) ; // If we are here, the code is correct.
 // Let's add a last check: whether there is a "return" keyword or not.
 if ( stripos ( $ code , "return" ) === false ) { throw new Error ( "Missing 'return' keyword." , count ( explode ( "\n" , $ codeString ) ) ) ; } }
This function will throw a PhpParser\Error exception if a parsing error is met in the code.

@param string $codeString
@throws \PhpParser\Error
This function will throw a PhpParser \ Error exception if a parsing error is met in the code .