private function detectTemplate() { foreach ($this->lexer->getTokens() as $token) { if (!is_array($token)) { continue; } $templateEndTokens = [T_ENDIF => 1, T_ENDFOREACH => 1, T_ENDFOR => 1, T_ENDWHILE => 1]; if (!isset($templateEndTokens[$token[0]])) { continue; } if (Strings::startsWith($token[1], 'end')) { throw new TemplateSkippedException(); } } }
/** * @dataProvider startsWithProvider */ public function testStartsWith($expected, $subject, $prefix) { $this->assertSame($expected, Strings::startsWith($subject, $prefix)); }
/** * displayList with keys and values. * * @param string[] $list List of elements to display. Keys can be integers or strings. * @param bool $singleLine Optional, defaults to false. If true, all elements will be shown on a single line. */ public function displayList($list, $singleLine = false) { $this->outln(); foreach ($list as $key => $value) { if (Strings::startsWith((string) $value, (string) $key)) { $this->out(sprintf('<<yellow>>%s<<reset>>%s', $key, mb_substr($value, mb_strlen($key)))); } else { $this->out(sprintf('<<yellow>>%s<<reset>> %s', $key, $value)); } if ($singleLine) { $this->out(' '); } else { $this->out(PHP_EOL); } } }
/** * @param \nochso\Omni\Multiline $lines * * @return string */ private function extractLongDescription(Multiline $lines) { $description = new Multiline(); $description->setEol((string) $lines->getEol()); $isFenced = false; for (; $this->position < count($lines); $this->position++) { $line = $lines[$this->position]; if (preg_match('/^```(?!`)/', $line) === 1) { $isFenced = !$isFenced; } if (!$isFenced && Strings::startsWith($line, '@')) { break; } $description->add($line); } return (string) $description; }
protected function compareClassMethodName(ClassMethod $a, ClassMethod $b) { $aIsMagic = Strings::startsWith($a->name, '__'); $bIsMagic = Strings::startsWith($b->name, '__'); // __magic goes first if ($aIsMagic || $bIsMagic) { return strcmp($bIsMagic, $aIsMagic); } // Check for accessors $regex = '/^(' . implode('|', $this->accessorPrefixes) . ')(([A-Z].*)?)$/'; $aAccessor = preg_match($regex, $a->name, $aMatches); $bAccessor = preg_match($regex, $b->name, $bMatches); $cmp = strcmp($bAccessor, $aAccessor); // Only one accessor: move it up. If no accessors, keep as is. if ($cmp !== 0 || !$aAccessor && !$bAccessor) { return $cmp; } // Both are accessors. If they have different suffixes, sort by it $cmp = strcmp($aMatches[2], $bMatches[2]); if ($cmp !== 0) { return $cmp; } // Accessors with identical suffix. Sort by accessor prefix priority $aPrio = array_search($aMatches[1], $this->accessorPrefixes, true); $bPrio = array_search($bMatches[1], $this->accessorPrefixes, true); return strcmp($aPrio, $bPrio); }
/** * @param string $line * @param string|null $prevLine * @param int $key * * @return \nochso\WriteMe\Markdown\Header|null */ private function extractHeader($line, $prevLine, $key) { // # ATX style header if (preg_match('/^(#+)\\s*(.+)\\s*#*$/', $line, $matches)) { return new Header(strlen($matches[1]), $matches[2], $key); } // SETEXT style header // ---------|========= if ($prevLine !== null && strlen($prevLine) !== 0 && preg_match('/^[=-]+$/', $line, $matches)) { $level = Strings::startsWith($line, '=') ? 1 : 2; return new Header($level, trim($prevLine), $key); } return null; }