本文整理汇总了PHP中Symfony\CS\Utils::cmpInt方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::cmpInt方法的具体用法?PHP Utils::cmpInt怎么用?PHP Utils::cmpInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\CS\Utils
的用法示例。
在下文中一共展示了Utils::cmpInt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBestDelimiter
private function getBestDelimiter($pattern)
{
$delimiters = array();
foreach (self::$delimiters as $k => $d) {
if (false === strpos($pattern, $d)) {
return $d;
}
$delimiters[$d] = array(substr_count($pattern, $d), $k);
}
uasort($delimiters, function ($a, $b) {
if ($a[0] === $b[0]) {
return Utils::cmpInt($a, $b);
}
return $a[0] < $b[0] ? -1 : 1;
});
return key($delimiters);
}
示例2: getFixersHelp
protected function getFixersHelp()
{
$help = '';
$maxName = 0;
$fixers = $this->fixer->getFixers();
// sort fixers by level and name
usort($fixers, function (FixerInterface $a, FixerInterface $b) {
$cmp = Utils::cmpInt($a->getLevel(), $b->getLevel());
if (0 !== $cmp) {
return $cmp;
}
return strcmp($a->getName(), $b->getName());
});
foreach ($fixers as $fixer) {
if (strlen($fixer->getName()) > $maxName) {
$maxName = strlen($fixer->getName());
}
}
$count = count($fixers) - 1;
foreach ($fixers as $i => $fixer) {
$chunks = explode("\n", wordwrap(sprintf("[%s]\n%s", $this->fixer->getLevelAsString($fixer), $fixer->getDescription()), 72 - $maxName, "\n"));
$help .= sprintf(" * <comment>%s</comment>%s %s\n", $fixer->getName(), str_repeat(' ', $maxName - strlen($fixer->getName())), array_shift($chunks));
while ($c = array_shift($chunks)) {
$help .= str_repeat(' ', $maxName + 4) . $c . "\n";
}
if ($count !== $i) {
$help .= "\n";
}
}
return $help;
}
示例3: sortFixers
private function sortFixers()
{
usort($this->fixers, function (FixerInterface $a, FixerInterface $b) {
return Utils::cmpInt($b->getPriority(), $a->getPriority());
});
}
示例4: sortFixers
/**
* Sort fixers by their priorities.
*
* @return $this
*/
private function sortFixers()
{
// Schwartzian transform is used to improve the efficiency and avoid
// `usort(): Array was modified by the user comparison function` warning for mocked objects.
$data = array_map(function (FixerInterface $fixer) {
return array($fixer, $fixer->getPriority());
}, $this->fixers);
usort($data, function (array $a, array $b) {
return Utils::cmpInt($b[1], $a[1]);
});
$this->fixers = array_map(function (array $item) {
return $item[0];
}, $data);
return $this;
}
示例5: sortTransformers
/**
* Sort registered Transformers.
*/
private function sortTransformers()
{
usort($this->items, function (TransformerInterface $a, TransformerInterface $b) {
return Utils::cmpInt($b->getPriority(), $a->getPriority());
});
}
示例6: sortFixers
/**
* @param FixerInterface[] $fixers
*
* @return FixerInterface[]
*/
private function sortFixers(array $fixers)
{
usort($fixers, function (FixerInterface $a, FixerInterface $b) {
return Utils::cmpInt($b->getPriority(), $a->getPriority());
});
return $fixers;
}
示例7: getBestDelimiter
/**
* Get the delimiter that would require the least escaping in a regular expression.
*
* @param string $pattern the regular expression
*
* @return string the preg delimiter
*/
private function getBestDelimiter($pattern)
{
// try do find something that's not used
$delimiters = array();
foreach (self::$delimiters as $k => $d) {
if (false === strpos($pattern, $d)) {
return $d;
}
$delimiters[$d] = array(substr_count($pattern, $d), $k);
}
// return the least used delimiter, using the position in the list as a tie breaker
uasort($delimiters, function ($a, $b) {
if ($a[0] === $b[0]) {
return Utils::cmpInt($a, $b);
}
return $a[0] < $b[0] ? -1 : 1;
});
return key($delimiters);
}
示例8: testCmpInt
/**
* @dataProvider provideCmpIntCases
*/
public function testCmpInt($expected, $left, $right)
{
$this->assertSame($expected, Utils::cmpInt($left, $right));
}