Skip to content

Commit

Permalink
Move constant defined check when setting the option value in YamlLinter
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Nov 21, 2017
1 parent a187136 commit a375508
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Linter/Yaml/YamlLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ private function parseYaml($content)
$flags = 0;
$flags |= $this->objectSupport ? Yaml::PARSE_OBJECT : 0;
$flags |= $this->exceptionOnInvalidType ? Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE : 0;

// Yaml::PARSE_CONSTANT is only available in Symfony Yaml >= 3.2
$flags |= $this->parseConstants && defined('Symfony\Component\Yaml\Yaml::PARSE_CONSTANT') ? Yaml::PARSE_CONSTANT : 0;

// Yaml::PARSE_CUSTOM_TAGS is only available in Symfony Yaml >= 3.3
$flags |= $this->parseCustomTags && defined('Symfony\Component\Yaml\Yaml::PARSE_CUSTOM_TAGS') ? Yaml::PARSE_CUSTOM_TAGS : 0;
$flags |= $this->parseConstants ? Yaml::PARSE_CONSTANT : 0;
$flags |= $this->parseCustomTags ? Yaml::PARSE_CUSTOM_TAGS : 0;
Yaml::parse($content, $flags);
}

Expand Down Expand Up @@ -146,14 +142,16 @@ public function setExceptionOnInvalidType($exceptionOnInvalidType)
*/
public function setParseCustomTags($parseCustomTags)
{
$this->parseCustomTags = $parseCustomTags;
// Yaml::PARSE_CONSTANT is only available in Symfony Yaml >= 3.2
$this->parseCustomTags = $parseCustomTags && defined('Symfony\Component\Yaml\Yaml::PARSE_CONSTANT');
}

/**
* @param bool $parseConstants
*/
public function setParseConstants($parseConstants)
{
$this->parseConstants = $parseConstants;
// Yaml::PARSE_CUSTOM_TAGS is only available in Symfony Yaml >= 3.3
$this->parseConstants = $parseConstants && defined('Symfony\Component\Yaml\Yaml::PARSE_CUSTOM_TAGS');
}
}

0 comments on commit a375508

Please sign in to comment.