id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
45,900
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.fixMuchLinesAfterDescription
private function fixMuchLinesAfterDescription(int $startLine, int $endLine): void { $this->file->getFixer()->beginChangeset(); (new LineHelper($this->file))->removeLines($startLine, $endLine); $this->file->getFixer()->endChangeset(); }
php
private function fixMuchLinesAfterDescription(int $startLine, int $endLine): void { $this->file->getFixer()->beginChangeset(); (new LineHelper($this->file))->removeLines($startLine, $endLine); $this->file->getFixer()->endChangeset(); }
[ "private", "function", "fixMuchLinesAfterDescription", "(", "int", "$", "startLine", ",", "int", "$", "endLine", ")", ":", "void", "{", "$", "this", "->", "file", "->", "getFixer", "(", ")", "->", "beginChangeset", "(", ")", ";", "(", "new", "LineHelper", ...
Fixes much lines after description. @param int $startLine Line to start removing @param int $endLine Line to end removing @return void
[ "Fixes", "much", "lines", "after", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L282-L289
45,901
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.fixDescriptionUcFirst
private function fixDescriptionUcFirst(int $descriptionStartPtr): void { $descStartToken = $this->tokens[$descriptionStartPtr]; $this->file->getFixer()->beginChangeset(); $this->file->getFixer()->replaceToken( $descriptionStartPtr, ucfirst($descStartToken['content']) ); $this->file->getFixer()->endChangeset(); }
php
private function fixDescriptionUcFirst(int $descriptionStartPtr): void { $descStartToken = $this->tokens[$descriptionStartPtr]; $this->file->getFixer()->beginChangeset(); $this->file->getFixer()->replaceToken( $descriptionStartPtr, ucfirst($descStartToken['content']) ); $this->file->getFixer()->endChangeset(); }
[ "private", "function", "fixDescriptionUcFirst", "(", "int", "$", "descriptionStartPtr", ")", ":", "void", "{", "$", "descStartToken", "=", "$", "this", "->", "tokens", "[", "$", "descriptionStartPtr", "]", ";", "$", "this", "->", "file", "->", "getFixer", "(...
Fixes the description uc first. @param int $descriptionStartPtr Pointer to the description start @return void
[ "Fixes", "the", "description", "uc", "first", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L298-L310
45,902
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php
TraitUseDeclarationSniff.checkDeclaration
private function checkDeclaration(int $usePos): void { $file = $this->getFile()->getBaseFile(); if (TokenHelper::findNextLocal($file, T_COMMA, $usePos + 1)) { $endPos = TokenHelper::findNext($file, [T_OPEN_CURLY_BRACKET, T_SEMICOLON], $usePos + 1); $tokens = $file->getTokens(); if ($tokens[$endPos]['code'] === T_OPEN_CURLY_BRACKET) { $file->addError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); } else { $fix = $file->addFixableError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); if ($fix) { $this->fixeUse($endPos, $usePos); } } } }
php
private function checkDeclaration(int $usePos): void { $file = $this->getFile()->getBaseFile(); if (TokenHelper::findNextLocal($file, T_COMMA, $usePos + 1)) { $endPos = TokenHelper::findNext($file, [T_OPEN_CURLY_BRACKET, T_SEMICOLON], $usePos + 1); $tokens = $file->getTokens(); if ($tokens[$endPos]['code'] === T_OPEN_CURLY_BRACKET) { $file->addError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); } else { $fix = $file->addFixableError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); if ($fix) { $this->fixeUse($endPos, $usePos); } } } }
[ "private", "function", "checkDeclaration", "(", "int", "$", "usePos", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", "->", "getBaseFile", "(", ")", ";", "if", "(", "TokenHelper", "::", "findNextLocal", "(", "$", "file"...
Checks the declaration of the given use position and registers and error if needed. @param int $usePos @return void
[ "Checks", "the", "declaration", "of", "the", "given", "use", "position", "and", "registers", "and", "error", "if", "needed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php#L60-L86
45,903
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php
TraitUseDeclarationSniff.fixeUse
protected function fixeUse(int $endPos, int $usePos): void { $indentation = $this->getIndentationForFix($usePos); $file = $this->getFile()->getBaseFile(); $fixer = $file->fixer; $fixer->beginChangeset(); $commaPointers = TokenHelper::findNextAll($file, T_COMMA, $usePos + 1, $endPos); foreach ($commaPointers as $commaPos) { $pointerAfterComma = TokenHelper::findNextEffective($file, $commaPos + 1); $fixer->replaceToken($commaPos, ';' . $file->eolChar . $indentation . 'use '); for ($i = $commaPos + 1; $i < $pointerAfterComma; $i++) { $fixer->replaceToken($i, ''); } } $fixer->endChangeset(); }
php
protected function fixeUse(int $endPos, int $usePos): void { $indentation = $this->getIndentationForFix($usePos); $file = $this->getFile()->getBaseFile(); $fixer = $file->fixer; $fixer->beginChangeset(); $commaPointers = TokenHelper::findNextAll($file, T_COMMA, $usePos + 1, $endPos); foreach ($commaPointers as $commaPos) { $pointerAfterComma = TokenHelper::findNextEffective($file, $commaPos + 1); $fixer->replaceToken($commaPos, ';' . $file->eolChar . $indentation . 'use '); for ($i = $commaPos + 1; $i < $pointerAfterComma; $i++) { $fixer->replaceToken($i, ''); } } $fixer->endChangeset(); }
[ "protected", "function", "fixeUse", "(", "int", "$", "endPos", ",", "int", "$", "usePos", ")", ":", "void", "{", "$", "indentation", "=", "$", "this", "->", "getIndentationForFix", "(", "$", "usePos", ")", ";", "$", "file", "=", "$", "this", "->", "g...
Fixes the given use position. @param int $endPos The end of the checked position. @param int $usePos @return void
[ "Fixes", "the", "given", "use", "position", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php#L96-L114
45,904
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php
TraitUseDeclarationSniff.getIndentationForFix
private function getIndentationForFix(int $usePos): string { $file = $this->getFile()->getBaseFile(); $indentation = ''; $currentPointer = $usePos - 1; $tokens = $file->getTokens(); while ($tokens[$currentPointer]['code'] === T_WHITESPACE && $tokens[$currentPointer]['content'] !== $file->eolChar) { $indentation .= $tokens[$currentPointer]['content']; $currentPointer--; } return $indentation; }
php
private function getIndentationForFix(int $usePos): string { $file = $this->getFile()->getBaseFile(); $indentation = ''; $currentPointer = $usePos - 1; $tokens = $file->getTokens(); while ($tokens[$currentPointer]['code'] === T_WHITESPACE && $tokens[$currentPointer]['content'] !== $file->eolChar) { $indentation .= $tokens[$currentPointer]['content']; $currentPointer--; } return $indentation; }
[ "private", "function", "getIndentationForFix", "(", "int", "$", "usePos", ")", ":", "string", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", "->", "getBaseFile", "(", ")", ";", "$", "indentation", "=", "''", ";", "$", "currentPointer", ...
Returns the needed indentation whitespace for fhe fixing of the uses. @param int $usePos @return string
[ "Returns", "the", "needed", "indentation", "whitespace", "for", "fhe", "fixing", "of", "the", "uses", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php#L123-L137
45,905
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php
UseStatementHelper.getType
public static function getType(File $file, UseStatement $useStatement): string { // Satisfy php md unset($file); $type = $useStatement->getType(); return $type; }
php
public static function getType(File $file, UseStatement $useStatement): string { // Satisfy php md unset($file); $type = $useStatement->getType(); return $type; }
[ "public", "static", "function", "getType", "(", "File", "$", "file", ",", "UseStatement", "$", "useStatement", ")", ":", "string", "{", "// Satisfy php md", "unset", "(", "$", "file", ")", ";", "$", "type", "=", "$", "useStatement", "->", "getType", "(", ...
Returns the type for the given use statement. @param File $file @param UseStatement $useStatement @return string
[ "Returns", "the", "type", "for", "the", "given", "use", "statement", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php#L27-L35
45,906
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php
UseStatementHelper.getTypeName
public static function getTypeName(File $file, UseStatement $useStatement): string { return UseStatement::getTypeName(static::getType($file, $useStatement)) ?? ''; }
php
public static function getTypeName(File $file, UseStatement $useStatement): string { return UseStatement::getTypeName(static::getType($file, $useStatement)) ?? ''; }
[ "public", "static", "function", "getTypeName", "(", "File", "$", "file", ",", "UseStatement", "$", "useStatement", ")", ":", "string", "{", "return", "UseStatement", "::", "getTypeName", "(", "static", "::", "getType", "(", "$", "file", ",", "$", "useStateme...
Returns the type name for the given use statement. @param File $file @param UseStatement $useStatement @return string
[ "Returns", "the", "type", "name", "for", "the", "given", "use", "statement", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php#L45-L48
45,907
mimmi20/BrowserDetector
src/Parser/DeviceParser.php
DeviceParser.parse
public function parse(string $useragent): array { if (preg_match('/new-sogou-spider|zollard|socialradarbot|microsoft office protocol discovery|powermarks|archivebot|marketwirebot|microsoft-cryptoapi|pad-bot|james bot|winhttp|jobboerse|<|>|online-versicherungsportal\.info|versicherungssuchmaschine\.net|microsearch|microsoft data access|microsoft url control|infegyatlas|msie or firefox mutant|semantic-visions\.com crawler|labs\.topsy\.com\/butterfly|dolphin http client|google wireless transcoder|commoncrawler|ipodder|tripadvisor|nokia wap gateway|outclicksbot/i', $useragent)) { return $this->load('unknown', 'unknown', $useragent); } if (!preg_match('/freebsd|raspbian/i', $useragent) && preg_match('/darwin|cfnetwork/i', $useragent) ) { return $this->darwinParser->parse($useragent); } if ($this->mobileDevice->isMobile($useragent)) { return $this->mobileParser->parse($useragent); } if ($this->tvDevice->isTvDevice($useragent)) { return $this->tvParser->parse($useragent); } if ($this->desktopDevice->isDesktopDevice($useragent)) { return $this->desktopParser->parse($useragent); } return $this->load('unknown', 'unknown', $useragent); }
php
public function parse(string $useragent): array { if (preg_match('/new-sogou-spider|zollard|socialradarbot|microsoft office protocol discovery|powermarks|archivebot|marketwirebot|microsoft-cryptoapi|pad-bot|james bot|winhttp|jobboerse|<|>|online-versicherungsportal\.info|versicherungssuchmaschine\.net|microsearch|microsoft data access|microsoft url control|infegyatlas|msie or firefox mutant|semantic-visions\.com crawler|labs\.topsy\.com\/butterfly|dolphin http client|google wireless transcoder|commoncrawler|ipodder|tripadvisor|nokia wap gateway|outclicksbot/i', $useragent)) { return $this->load('unknown', 'unknown', $useragent); } if (!preg_match('/freebsd|raspbian/i', $useragent) && preg_match('/darwin|cfnetwork/i', $useragent) ) { return $this->darwinParser->parse($useragent); } if ($this->mobileDevice->isMobile($useragent)) { return $this->mobileParser->parse($useragent); } if ($this->tvDevice->isTvDevice($useragent)) { return $this->tvParser->parse($useragent); } if ($this->desktopDevice->isDesktopDevice($useragent)) { return $this->desktopParser->parse($useragent); } return $this->load('unknown', 'unknown', $useragent); }
[ "public", "function", "parse", "(", "string", "$", "useragent", ")", ":", "array", "{", "if", "(", "preg_match", "(", "'/new-sogou-spider|zollard|socialradarbot|microsoft office protocol discovery|powermarks|archivebot|marketwirebot|microsoft-cryptoapi|pad-bot|james bot|winhttp|jobboer...
Gets the information about the rendering engine by User Agent @param string $useragent @throws \BrowserDetector\Loader\NotFoundException @return array
[ "Gets", "the", "information", "about", "the", "rendering", "engine", "by", "User", "Agent" ]
1b90d994fcee01344a36bbe39afb14622bc8df9c
https://github.com/mimmi20/BrowserDetector/blob/1b90d994fcee01344a36bbe39afb14622bc8df9c/src/Parser/DeviceParser.php#L104-L129
45,908
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.checkAndRegisterTagMaximumCounts
private function checkAndRegisterTagMaximumCounts(): void { $allTags = $this->getAllTags(); $checkedTags = []; $tagRules = $this->getRulesWithRequirement('max'); array_walk( $allTags, // TODO: Removed Duplicates function (array $tag, int $tagPos) use (&$checkedTags, $tagRules): void { $tagContent = substr($tag['content'], 1); if (!in_array($tagContent, $checkedTags)) { $checkedTags[] = $tagContent; $tagCount = count($this->findTokensForTag($tagContent)); $maxCount = @$tagRules[$tagContent]['max'] ?? 0; if ($maxCount && ($tagCount > $maxCount)) { $this->file->addError( self::MESSAGE_TAG_OCCURRENCE_MAX, $tagPos, // We use an error code containing the tag name because we can't configure this rules from // the outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MAX_PREFIX . ucfirst($tagContent), [ $tagContent, $maxCount, $tagCount ] ); } } } ); }
php
private function checkAndRegisterTagMaximumCounts(): void { $allTags = $this->getAllTags(); $checkedTags = []; $tagRules = $this->getRulesWithRequirement('max'); array_walk( $allTags, // TODO: Removed Duplicates function (array $tag, int $tagPos) use (&$checkedTags, $tagRules): void { $tagContent = substr($tag['content'], 1); if (!in_array($tagContent, $checkedTags)) { $checkedTags[] = $tagContent; $tagCount = count($this->findTokensForTag($tagContent)); $maxCount = @$tagRules[$tagContent]['max'] ?? 0; if ($maxCount && ($tagCount > $maxCount)) { $this->file->addError( self::MESSAGE_TAG_OCCURRENCE_MAX, $tagPos, // We use an error code containing the tag name because we can't configure this rules from // the outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MAX_PREFIX . ucfirst($tagContent), [ $tagContent, $maxCount, $tagCount ] ); } } } ); }
[ "private", "function", "checkAndRegisterTagMaximumCounts", "(", ")", ":", "void", "{", "$", "allTags", "=", "$", "this", "->", "getAllTags", "(", ")", ";", "$", "checkedTags", "=", "[", "]", ";", "$", "tagRules", "=", "$", "this", "->", "getRulesWithRequir...
Loads the rules with amax rule and checks if there are more tags than allowed. @return void
[ "Loads", "the", "rules", "with", "amax", "rule", "and", "checks", "if", "there", "are", "more", "tags", "than", "allowed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L82-L117
45,909
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.checkAndRegisterTagMinimumCounts
private function checkAndRegisterTagMinimumCounts(): void { $checkedRule = 'min'; $rulesWithReq = $this->getRulesWithRequirement($checkedRule); array_walk( $rulesWithReq, function (array $tagRule, string $tag) use ($checkedRule): void { $minCount = $tagRule[$checkedRule]; $tagCount = count($this->findTokensForTag($tag)); if ($minCount > $tagCount) { $fixCallback = $this->hasFixCallback($checkedRule, $tag); $method = $fixCallback ? 'addFixableError' : 'addError'; $fixable = $this->file->{$method}( self::MESSAGE_TAG_OCCURRENCE_MIN, $this->getDocCommentPos(), // We use an error code containing the tag name because we can't configure this rules from the // outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MIN_PREFIX . ucfirst($tag), [ $tag, $minCount, $tagCount ] ); if ($fixable && $fixCallback) { $this->{$fixCallback}($this->getDocCommentPos(), $minCount, $tagCount, $tag); } } } ); }
php
private function checkAndRegisterTagMinimumCounts(): void { $checkedRule = 'min'; $rulesWithReq = $this->getRulesWithRequirement($checkedRule); array_walk( $rulesWithReq, function (array $tagRule, string $tag) use ($checkedRule): void { $minCount = $tagRule[$checkedRule]; $tagCount = count($this->findTokensForTag($tag)); if ($minCount > $tagCount) { $fixCallback = $this->hasFixCallback($checkedRule, $tag); $method = $fixCallback ? 'addFixableError' : 'addError'; $fixable = $this->file->{$method}( self::MESSAGE_TAG_OCCURRENCE_MIN, $this->getDocCommentPos(), // We use an error code containing the tag name because we can't configure this rules from the // outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MIN_PREFIX . ucfirst($tag), [ $tag, $minCount, $tagCount ] ); if ($fixable && $fixCallback) { $this->{$fixCallback}($this->getDocCommentPos(), $minCount, $tagCount, $tag); } } } ); }
[ "private", "function", "checkAndRegisterTagMinimumCounts", "(", ")", ":", "void", "{", "$", "checkedRule", "=", "'min'", ";", "$", "rulesWithReq", "=", "$", "this", "->", "getRulesWithRequirement", "(", "$", "checkedRule", ")", ";", "array_walk", "(", "$", "ru...
Checks if the tag occurrences reaches their minimum counts. @return void
[ "Checks", "if", "the", "tag", "occurrences", "reaches", "their", "minimum", "counts", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L124-L157
45,910
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.findTokensForTag
private function findTokensForTag(string $tagName): array { $allTags = $this->getAllTags(); return array_filter($allTags, function (array $tag) use ($tagName): bool { return substr($tag['content'], 1) === $tagName; }); }
php
private function findTokensForTag(string $tagName): array { $allTags = $this->getAllTags(); return array_filter($allTags, function (array $tag) use ($tagName): bool { return substr($tag['content'], 1) === $tagName; }); }
[ "private", "function", "findTokensForTag", "(", "string", "$", "tagName", ")", ":", "array", "{", "$", "allTags", "=", "$", "this", "->", "getAllTags", "(", ")", ";", "return", "array_filter", "(", "$", "allTags", ",", "function", "(", "array", "$", "tag...
Returns only the tokens with the given tag name. @param string $tagName @return array
[ "Returns", "only", "the", "tokens", "with", "the", "given", "tag", "name", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L166-L173
45,911
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.getProcessedTagRules
private function getProcessedTagRules(): array { if ($this->processedTagRules === null) { $this->processedTagRules = $this->processTagRules(); } return $this->processedTagRules; }
php
private function getProcessedTagRules(): array { if ($this->processedTagRules === null) { $this->processedTagRules = $this->processTagRules(); } return $this->processedTagRules; }
[ "private", "function", "getProcessedTagRules", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "processedTagRules", "===", "null", ")", "{", "$", "this", "->", "processedTagRules", "=", "$", "this", "->", "processTagRules", "(", ")", ";", "}", ...
Returns the rules with their resolved callbacks. @return array
[ "Returns", "the", "rules", "with", "their", "resolved", "callbacks", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L194-L201
45,912
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.getRulesWithRequirement
private function getRulesWithRequirement(string $requiredRule): array { $processedTagRules = $this->getProcessedTagRules(); $processedTagRules = array_filter($processedTagRules, function (array $tagRule) use ($requiredRule): bool { return array_key_exists($requiredRule, $tagRule); }); return $processedTagRules; }
php
private function getRulesWithRequirement(string $requiredRule): array { $processedTagRules = $this->getProcessedTagRules(); $processedTagRules = array_filter($processedTagRules, function (array $tagRule) use ($requiredRule): bool { return array_key_exists($requiredRule, $tagRule); }); return $processedTagRules; }
[ "private", "function", "getRulesWithRequirement", "(", "string", "$", "requiredRule", ")", ":", "array", "{", "$", "processedTagRules", "=", "$", "this", "->", "getProcessedTagRules", "(", ")", ";", "$", "processedTagRules", "=", "array_filter", "(", "$", "proce...
Returns the rules with the given requirement. @param string $requiredRule @return array
[ "Returns", "the", "rules", "with", "the", "given", "requirement", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L210-L218
45,913
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.hasFixCallback
private function hasFixCallback(string $rule, string $tag) { return method_exists($this, $method = sprintf('fix%s%s', ucfirst($rule), ucfirst($tag))) ? $method : false; }
php
private function hasFixCallback(string $rule, string $tag) { return method_exists($this, $method = sprintf('fix%s%s', ucfirst($rule), ucfirst($tag))) ? $method : false; }
[ "private", "function", "hasFixCallback", "(", "string", "$", "rule", ",", "string", "$", "tag", ")", "{", "return", "method_exists", "(", "$", "this", ",", "$", "method", "=", "sprintf", "(", "'fix%s%s'", ",", "ucfirst", "(", "$", "rule", ")", ",", "uc...
Returns true if there is a callback for the given rule and tag. @param string $rule @param string $tag @return bool|string
[ "Returns", "true", "if", "there", "is", "a", "callback", "for", "the", "given", "rule", "and", "tag", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L237-L242
45,914
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.processTagRules
private function processTagRules(): array { $processedTagRules = $this->getTagRules(); array_walk($processedTagRules, function (&$tagRule) { $tagRule = array_map(function ($valueOrCallback) { return is_callable($valueOrCallback, true) ? Closure::fromCallable($valueOrCallback)->call($this) : $valueOrCallback; }, $tagRule); }); return $processedTagRules; }
php
private function processTagRules(): array { $processedTagRules = $this->getTagRules(); array_walk($processedTagRules, function (&$tagRule) { $tagRule = array_map(function ($valueOrCallback) { return is_callable($valueOrCallback, true) ? Closure::fromCallable($valueOrCallback)->call($this) : $valueOrCallback; }, $tagRule); }); return $processedTagRules; }
[ "private", "function", "processTagRules", "(", ")", ":", "array", "{", "$", "processedTagRules", "=", "$", "this", "->", "getTagRules", "(", ")", ";", "array_walk", "(", "$", "processedTagRules", ",", "function", "(", "&", "$", "tagRule", ")", "{", "$", ...
Resolves the callbacks in the tag rules. @return array
[ "Resolves", "the", "callbacks", "in", "the", "tag", "rules", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L264-L277
45,915
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.tearDown
protected function tearDown(): void { parent::tearDown(); $this->resetDocCommentPos(); $this->processedTagRules = null; $this->tags = null; }
php
protected function tearDown(): void { parent::tearDown(); $this->resetDocCommentPos(); $this->processedTagRules = null; $this->tags = null; }
[ "protected", "function", "tearDown", "(", ")", ":", "void", "{", "parent", "::", "tearDown", "(", ")", ";", "$", "this", "->", "resetDocCommentPos", "(", ")", ";", "$", "this", "->", "processedTagRules", "=", "null", ";", "$", "this", "->", "tags", "="...
Resets the cached data. @return void
[ "Resets", "the", "cached", "data", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L295-L303
45,916
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.checkAndRegisterLineBreakErrors
private function checkAndRegisterLineBreakErrors(): void { $tokens = $this->getTagTokens(); $prevToken = []; $tagCounts = $this->docTagHelper->getTagCounts($tokens); $withReturn = false; foreach ($tokens as $tokenPos => $token) { $thisTagContent = $token['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevToken && ($prevToken['content'] !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups or before the return tag if there is no line break already. if ($isGroupSwitch && (($prevToken['line'] + 1) === $token['line'])) { $isFixing = $this->file->addFixableWarning( static::MESSAGE_MISSING_NEWLINE_BETWEEN_TAGS, $tokenPos, static::CODE_MISSING_NEWLINE_BETWEEN_TAGS, [ $prevToken['content'] ] ); if ($isFixing) { $this->insertNewLine($token); } } $prevToken = $token; // Return should be the last element, so this is ok. $withReturn = $isReturn; } }
php
private function checkAndRegisterLineBreakErrors(): void { $tokens = $this->getTagTokens(); $prevToken = []; $tagCounts = $this->docTagHelper->getTagCounts($tokens); $withReturn = false; foreach ($tokens as $tokenPos => $token) { $thisTagContent = $token['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevToken && ($prevToken['content'] !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups or before the return tag if there is no line break already. if ($isGroupSwitch && (($prevToken['line'] + 1) === $token['line'])) { $isFixing = $this->file->addFixableWarning( static::MESSAGE_MISSING_NEWLINE_BETWEEN_TAGS, $tokenPos, static::CODE_MISSING_NEWLINE_BETWEEN_TAGS, [ $prevToken['content'] ] ); if ($isFixing) { $this->insertNewLine($token); } } $prevToken = $token; // Return should be the last element, so this is ok. $withReturn = $isReturn; } }
[ "private", "function", "checkAndRegisterLineBreakErrors", "(", ")", ":", "void", "{", "$", "tokens", "=", "$", "this", "->", "getTagTokens", "(", ")", ";", "$", "prevToken", "=", "[", "]", ";", "$", "tagCounts", "=", "$", "this", "->", "docTagHelper", "-...
Checks for line break errors and registers the errors if there are any. This should be called after the sorting is already checked and fixed! @return void
[ "Checks", "for", "line", "break", "errors", "and", "registers", "the", "errors", "if", "there", "are", "any", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L87-L124
45,917
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.checkAndRegisterSortingError
private function checkAndRegisterSortingError(): void { $orgTokens = $this->getTagTokens(); $sortedTokens = $this->sortTokens($orgTokens); if (array_values($orgTokens) !== $sortedTokens) { $error = (new CodeWarning( static::CODE_WRONG_TAG_SORTING, self::MESSAGE_WRONG_TAG_SORTING, array_shift($orgTokens)['pointer'] ))->setToken($this->token); $error->isFixable(true); throw $error; } }
php
private function checkAndRegisterSortingError(): void { $orgTokens = $this->getTagTokens(); $sortedTokens = $this->sortTokens($orgTokens); if (array_values($orgTokens) !== $sortedTokens) { $error = (new CodeWarning( static::CODE_WRONG_TAG_SORTING, self::MESSAGE_WRONG_TAG_SORTING, array_shift($orgTokens)['pointer'] ))->setToken($this->token); $error->isFixable(true); throw $error; } }
[ "private", "function", "checkAndRegisterSortingError", "(", ")", ":", "void", "{", "$", "orgTokens", "=", "$", "this", "->", "getTagTokens", "(", ")", ";", "$", "sortedTokens", "=", "$", "this", "->", "sortTokens", "(", "$", "orgTokens", ")", ";", "if", ...
Checks the alphabetic sorting and registers and error if it sorted wrongly. @throws CodeWarning If the tags are not correctly sorted. @return void
[ "Checks", "the", "alphabetic", "sorting", "and", "registers", "and", "error", "if", "it", "sorted", "wrongly", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L133-L149
45,918
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.compareTokensForSorting
private function compareTokensForSorting(array $leftToken, array $rightToken, array $tagCounts): int { $leftTagName = $leftToken['content']; $rightTagName = $rightToken['content']; $realLeftTagName = $this->getRealtagName($leftTagName); $realRightTagName = $this->getRealtagName($rightTagName); // If they have the same content, leave them, where they where ... $return = $leftToken['line'] > $rightToken['line'] ? 1 : -1; // But if they are different. if ($realLeftTagName !== $realRightTagName) { $leftTagCount = $tagCounts[$leftTagName]; $rightTagCount = $tagCounts[$rightTagName]; switch (true) { // Move return to bottom everytime ... case ($realLeftTagName === '@return'): $return = 1; break; // ... yes, everytime case ($realRightTagName === '@return'): $return = -1; break; // Move single items to the top. case ($leftTagCount !== $rightTagCount): $return = $leftTagCount > $rightTagCount ? +1 : -1; break; // Compare tag name default: $return = strcasecmp($realLeftTagName, $realRightTagName) > 1 ? 1 : -1; } } return $return; }
php
private function compareTokensForSorting(array $leftToken, array $rightToken, array $tagCounts): int { $leftTagName = $leftToken['content']; $rightTagName = $rightToken['content']; $realLeftTagName = $this->getRealtagName($leftTagName); $realRightTagName = $this->getRealtagName($rightTagName); // If they have the same content, leave them, where they where ... $return = $leftToken['line'] > $rightToken['line'] ? 1 : -1; // But if they are different. if ($realLeftTagName !== $realRightTagName) { $leftTagCount = $tagCounts[$leftTagName]; $rightTagCount = $tagCounts[$rightTagName]; switch (true) { // Move return to bottom everytime ... case ($realLeftTagName === '@return'): $return = 1; break; // ... yes, everytime case ($realRightTagName === '@return'): $return = -1; break; // Move single items to the top. case ($leftTagCount !== $rightTagCount): $return = $leftTagCount > $rightTagCount ? +1 : -1; break; // Compare tag name default: $return = strcasecmp($realLeftTagName, $realRightTagName) > 1 ? 1 : -1; } } return $return; }
[ "private", "function", "compareTokensForSorting", "(", "array", "$", "leftToken", ",", "array", "$", "rightToken", ",", "array", "$", "tagCounts", ")", ":", "int", "{", "$", "leftTagName", "=", "$", "leftToken", "[", "'content'", "]", ";", "$", "rightTagName...
The callback to sort tokens. 1. @return goes to the bottom 2. Single tags are group alphabetically in the top group. 3. Groups are sorted then by occurrence, that the largest group is the last one before the return. 4. Same annotations are kept in the order of their code. @param array $leftToken Provided by usort. @param array $rightToken Provided by usort. @param array $tagCounts Saves the occurence count for every tag. @return int
[ "The", "callback", "to", "sort", "tokens", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L165-L203
45,919
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.createNewSortedTagsContent
private function createNewSortedTagsContent(): string { $file = $this->file; $eolChar = $file->getEolChar(); $newContent = ''; $prevTagContent = ''; $sortedTags = $this->sortTokens($this->getTagTokens()); $tagCounts = $this->docTagHelper->getTagCounts($sortedTags); $withReturn = false; foreach ($sortedTags as $tag) { $lineStartingPadding = str_pad('', $tag['column'] - 3, ' '); $thisTagContent = $tag['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevTagContent && ($prevTagContent !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups. if ($isGroupSwitch) { $newContent .= $lineStartingPadding . '*' . $eolChar; } // Create the new Tag. // WARNING We do not need a line break in the tag summary. $newContent .= $lineStartingPadding . '* ' . trim($thisTagContent); if ($tag['contents']) { $prevLine = $tag['line']; foreach ($tag['contents'] as $subToken) { // If we have a line switch, we need to create the correct indentation from before ... if ($withLineSwitch = $subToken['line'] > $prevLine) { $newContent .= $eolChar . $lineStartingPadding . '*' . str_repeat(' ', $subToken['column'] - strlen($lineStartingPadding) - 2); $prevLine = $subToken['line']; } // ... if we have no line switch, then an additional whitespace is enough. $newContent .= ($withLineSwitch ? '' : ' ') . $subToken['content']; } } $newContent .= $eolChar; $prevTagContent = $thisTagContent; $withReturn = $isReturn; } $newContent .= $lineStartingPadding . '*/' . $eolChar; return $newContent; }
php
private function createNewSortedTagsContent(): string { $file = $this->file; $eolChar = $file->getEolChar(); $newContent = ''; $prevTagContent = ''; $sortedTags = $this->sortTokens($this->getTagTokens()); $tagCounts = $this->docTagHelper->getTagCounts($sortedTags); $withReturn = false; foreach ($sortedTags as $tag) { $lineStartingPadding = str_pad('', $tag['column'] - 3, ' '); $thisTagContent = $tag['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevTagContent && ($prevTagContent !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups. if ($isGroupSwitch) { $newContent .= $lineStartingPadding . '*' . $eolChar; } // Create the new Tag. // WARNING We do not need a line break in the tag summary. $newContent .= $lineStartingPadding . '* ' . trim($thisTagContent); if ($tag['contents']) { $prevLine = $tag['line']; foreach ($tag['contents'] as $subToken) { // If we have a line switch, we need to create the correct indentation from before ... if ($withLineSwitch = $subToken['line'] > $prevLine) { $newContent .= $eolChar . $lineStartingPadding . '*' . str_repeat(' ', $subToken['column'] - strlen($lineStartingPadding) - 2); $prevLine = $subToken['line']; } // ... if we have no line switch, then an additional whitespace is enough. $newContent .= ($withLineSwitch ? '' : ' ') . $subToken['content']; } } $newContent .= $eolChar; $prevTagContent = $thisTagContent; $withReturn = $isReturn; } $newContent .= $lineStartingPadding . '*/' . $eolChar; return $newContent; }
[ "private", "function", "createNewSortedTagsContent", "(", ")", ":", "string", "{", "$", "file", "=", "$", "this", "->", "file", ";", "$", "eolChar", "=", "$", "file", "->", "getEolChar", "(", ")", ";", "$", "newContent", "=", "''", ";", "$", "prevTagCo...
Sorts the tags and creates a new doc comment part for them to replace it with the old content. @return string The new content.
[ "Sorts", "the", "tags", "and", "creates", "a", "new", "doc", "comment", "part", "for", "them", "to", "replace", "it", "with", "the", "old", "content", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L210-L266
45,920
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.fixSorting
private function fixSorting(): void { $fixer = $this->file->getFixer(); $fixer->beginChangeset(); $firstTag = $this->removeOldTagLines(); $fixer->addContent($firstTag['pointer'] - 1, $this->createNewSortedTagsContent()); $fixer->endChangeset(); }
php
private function fixSorting(): void { $fixer = $this->file->getFixer(); $fixer->beginChangeset(); $firstTag = $this->removeOldTagLines(); $fixer->addContent($firstTag['pointer'] - 1, $this->createNewSortedTagsContent()); $fixer->endChangeset(); }
[ "private", "function", "fixSorting", "(", ")", ":", "void", "{", "$", "fixer", "=", "$", "this", "->", "file", "->", "getFixer", "(", ")", ";", "$", "fixer", "->", "beginChangeset", "(", ")", ";", "$", "firstTag", "=", "$", "this", "->", "removeOldTa...
Sorts the tokens in blocks of their occurences and then alphabetically, but the return at last. @return void
[ "Sorts", "the", "tokens", "in", "blocks", "of", "their", "occurences", "and", "then", "alphabetically", "but", "the", "return", "at", "last", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L273-L284
45,921
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.getTagTokens
private function getTagTokens(): array { if ($this->loadedTagTokens === null) { $this->loadedTagTokens = $this->loadTagTokens(); } return $this->loadedTagTokens; }
php
private function getTagTokens(): array { if ($this->loadedTagTokens === null) { $this->loadedTagTokens = $this->loadTagTokens(); } return $this->loadedTagTokens; }
[ "private", "function", "getTagTokens", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "loadedTagTokens", "===", "null", ")", "{", "$", "this", "->", "loadedTagTokens", "=", "$", "this", "->", "loadTagTokens", "(", ")", ";", "}", "return", "...
Returns the tokens of the comment tags. @return array The tokens of the comment tags.
[ "Returns", "the", "tokens", "of", "the", "comment", "tags", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L307-L314
45,922
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.insertNewLine
private function insertNewLine(array $token): void { $fixer = $this->file->getFixer(); $lineStartPadding = str_pad('', $token['column'] - 3, ' '); $fixer->beginChangeset(); // Remove the whitespace between the tag and the comments star. $fixer->replaceToken($token['pointer'] - 1, ''); $fixer->addContentBefore( $token['pointer'], $this->file->getEolChar() . $lineStartPadding . '* ' ); $fixer->endChangeset(); }
php
private function insertNewLine(array $token): void { $fixer = $this->file->getFixer(); $lineStartPadding = str_pad('', $token['column'] - 3, ' '); $fixer->beginChangeset(); // Remove the whitespace between the tag and the comments star. $fixer->replaceToken($token['pointer'] - 1, ''); $fixer->addContentBefore( $token['pointer'], $this->file->getEolChar() . $lineStartPadding . '* ' ); $fixer->endChangeset(); }
[ "private", "function", "insertNewLine", "(", "array", "$", "token", ")", ":", "void", "{", "$", "fixer", "=", "$", "this", "->", "file", "->", "getFixer", "(", ")", ";", "$", "lineStartPadding", "=", "str_pad", "(", "''", ",", "$", "token", "[", "'co...
Insert the new line before the given token. @param array $token The token where a newline should be. @return void
[ "Insert", "the", "new", "line", "before", "the", "given", "token", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L323-L339
45,923
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.loadTagTokens
private function loadTagTokens(): array { $barrier = 0; $tokens = $this->docTagHelper->getTagTokens(); $tokens = array_filter($tokens, function (array $token) use (&$barrier): bool { $allowed = true; if ($barrier) { if ($allowed = $token['column'] <= $barrier) { $barrier = 0; } } if ($allowed && array_key_exists('contents', $token)) { $barrier = $token['column']; } return $allowed; }); return $tokens; }
php
private function loadTagTokens(): array { $barrier = 0; $tokens = $this->docTagHelper->getTagTokens(); $tokens = array_filter($tokens, function (array $token) use (&$barrier): bool { $allowed = true; if ($barrier) { if ($allowed = $token['column'] <= $barrier) { $barrier = 0; } } if ($allowed && array_key_exists('contents', $token)) { $barrier = $token['column']; } return $allowed; }); return $tokens; }
[ "private", "function", "loadTagTokens", "(", ")", ":", "array", "{", "$", "barrier", "=", "0", ";", "$", "tokens", "=", "$", "this", "->", "docTagHelper", "->", "getTagTokens", "(", ")", ";", "$", "tokens", "=", "array_filter", "(", "$", "tokens", ",",...
Loads the tokens of this comment. @return array
[ "Loads", "the", "tokens", "of", "this", "comment", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L346-L368
45,924
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.processToken
protected function processToken(): void { try { $this->checkAndRegisterSortingError(); $this->checkAndRegisterLineBreakErrors(); } catch (CodeWarning $exception) { $fixable = $this->getExceptionHandler()->handleException($exception); if ($fixable) { $this->fixSorting(); } } }
php
protected function processToken(): void { try { $this->checkAndRegisterSortingError(); $this->checkAndRegisterLineBreakErrors(); } catch (CodeWarning $exception) { $fixable = $this->getExceptionHandler()->handleException($exception); if ($fixable) { $this->fixSorting(); } } }
[ "protected", "function", "processToken", "(", ")", ":", "void", "{", "try", "{", "$", "this", "->", "checkAndRegisterSortingError", "(", ")", ";", "$", "this", "->", "checkAndRegisterLineBreakErrors", "(", ")", ";", "}", "catch", "(", "CodeWarning", "$", "ex...
Processes a found registered token. @return void
[ "Processes", "a", "found", "registered", "token", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L375-L388
45,925
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.removeOldTagLines
private function removeOldTagLines(): array { $tags = $this->getTagTokens(); $firstTag = array_shift($tags); (new LineHelper($this->file)) ->removeLines( $firstTag['line'], $this->tokens[$this->token['comment_closer']]['line'] ); return $firstTag; }
php
private function removeOldTagLines(): array { $tags = $this->getTagTokens(); $firstTag = array_shift($tags); (new LineHelper($this->file)) ->removeLines( $firstTag['line'], $this->tokens[$this->token['comment_closer']]['line'] ); return $firstTag; }
[ "private", "function", "removeOldTagLines", "(", ")", ":", "array", "{", "$", "tags", "=", "$", "this", "->", "getTagTokens", "(", ")", ";", "$", "firstTag", "=", "array_shift", "(", "$", "tags", ")", ";", "(", "new", "LineHelper", "(", "$", "this", ...
Removed the lines with the wrongly sorted tags. @return array The first tag token of this doc block.
[ "Removed", "the", "lines", "with", "the", "wrongly", "sorted", "tags", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L405-L417
45,926
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.setUp
protected function setUp(): void { $this->addPointerToTokens(); $this->docTagHelper = new DocTagHelper( $this->file, $this->stackPos, $this->tokens ); }
php
protected function setUp(): void { $this->addPointerToTokens(); $this->docTagHelper = new DocTagHelper( $this->file, $this->stackPos, $this->tokens ); }
[ "protected", "function", "setUp", "(", ")", ":", "void", "{", "$", "this", "->", "addPointerToTokens", "(", ")", ";", "$", "this", "->", "docTagHelper", "=", "new", "DocTagHelper", "(", "$", "this", "->", "file", ",", "$", "this", "->", "stackPos", ","...
Do you want to setup things before processing the token? @return void
[ "Do", "you", "want", "to", "setup", "things", "before", "processing", "the", "token?" ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L424-L433
45,927
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.sortTokens
private function sortTokens(array $tokens): array { $tagCounts = $this->docTagHelper->getTagCounts($tokens); usort($tokens, function (array $leftToken, array $rightToken) use ($tagCounts): int { return $this->compareTokensForSorting($leftToken, $rightToken, $tagCounts); }); return $tokens; }
php
private function sortTokens(array $tokens): array { $tagCounts = $this->docTagHelper->getTagCounts($tokens); usort($tokens, function (array $leftToken, array $rightToken) use ($tagCounts): int { return $this->compareTokensForSorting($leftToken, $rightToken, $tagCounts); }); return $tokens; }
[ "private", "function", "sortTokens", "(", "array", "$", "tokens", ")", ":", "array", "{", "$", "tagCounts", "=", "$", "this", "->", "docTagHelper", "->", "getTagCounts", "(", "$", "tokens", ")", ";", "usort", "(", "$", "tokens", ",", "function", "(", "...
Sorts the tokens in blocks of their occurrences and then alphabetically, but the return at last. @param array $tokens The tokens. @return array The sorted tokens.
[ "Sorts", "the", "tokens", "in", "blocks", "of", "their", "occurrences", "and", "then", "alphabetically", "but", "the", "return", "at", "last", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L442-L451
45,928
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php
EmptyArrayForComparisonSniff.checkArrayStructure
private function checkArrayStructure(array $invalidCodes, int $searchPos): void { // Rename the var to get more readable code. $remainingInvalidCodes = $invalidCodes; unset($invalidCodes); foreach ($remainingInvalidCodes as $nextInvalidCodeIndex => $nextInvalidCode) { $foundTokenPos = TokenHelper::findNextEffective($this->getFile(), $searchPos); $foundToken = $this->tokens[$foundTokenPos]; // We can stop the search, if there is no invalid code. if ($foundToken['code'] !== $nextInvalidCode) { break; } // Check the next possible token $searchPos = $foundTokenPos + 1; unset($remainingInvalidCodes[$nextInvalidCodeIndex]); } $matchedEveryInvalidCode = !$remainingInvalidCodes; $this->file->recordMetric( $searchPos, 'Invalid array comparison', $matchedEveryInvalidCode ? 'yes' : 'no' ); if ($matchedEveryInvalidCode) { throw (new CodeError(static::CODE_EMPTY_ARRAY, self::MESSAGE_EMPTY_ARRAY, $searchPos)); } }
php
private function checkArrayStructure(array $invalidCodes, int $searchPos): void { // Rename the var to get more readable code. $remainingInvalidCodes = $invalidCodes; unset($invalidCodes); foreach ($remainingInvalidCodes as $nextInvalidCodeIndex => $nextInvalidCode) { $foundTokenPos = TokenHelper::findNextEffective($this->getFile(), $searchPos); $foundToken = $this->tokens[$foundTokenPos]; // We can stop the search, if there is no invalid code. if ($foundToken['code'] !== $nextInvalidCode) { break; } // Check the next possible token $searchPos = $foundTokenPos + 1; unset($remainingInvalidCodes[$nextInvalidCodeIndex]); } $matchedEveryInvalidCode = !$remainingInvalidCodes; $this->file->recordMetric( $searchPos, 'Invalid array comparison', $matchedEveryInvalidCode ? 'yes' : 'no' ); if ($matchedEveryInvalidCode) { throw (new CodeError(static::CODE_EMPTY_ARRAY, self::MESSAGE_EMPTY_ARRAY, $searchPos)); } }
[ "private", "function", "checkArrayStructure", "(", "array", "$", "invalidCodes", ",", "int", "$", "searchPos", ")", ":", "void", "{", "// Rename the var to get more readable code.", "$", "remainingInvalidCodes", "=", "$", "invalidCodes", ";", "unset", "(", "$", "inv...
Search starting with the given search pos for the invalid codes in consecutive order. @throws CodeError Contains the error message if there is an invalid array check. @param array $invalidCodes @param int $searchPos @return void
[ "Search", "starting", "with", "the", "given", "search", "pos", "for", "the", "invalid", "codes", "in", "consecutive", "order", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php#L56-L87
45,929
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php
EmptyArrayForComparisonSniff.setUp
protected function setUp(): void { parent::setUp(); $this->invalidStructure = [ T_ARRAY => [T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS], T_OPEN_SHORT_ARRAY => [T_CLOSE_SHORT_ARRAY] ]; }
php
protected function setUp(): void { parent::setUp(); $this->invalidStructure = [ T_ARRAY => [T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS], T_OPEN_SHORT_ARRAY => [T_CLOSE_SHORT_ARRAY] ]; }
[ "protected", "function", "setUp", "(", ")", ":", "void", "{", "parent", "::", "setUp", "(", ")", ";", "$", "this", "->", "invalidStructure", "=", "[", "T_ARRAY", "=>", "[", "T_OPEN_PARENTHESIS", ",", "T_CLOSE_PARENTHESIS", "]", ",", "T_OPEN_SHORT_ARRAY", "=>...
Declares the forbidden array structure. @return void
[ "Declares", "the", "forbidden", "array", "structure", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php#L142-L150
45,930
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php
DocTagHelper.getTagTokens
public function getTagTokens(): array { $iteratedPos = 0; $tagPositions = $this->getCommentStartToken()['comment_tags']; $tagTokens = []; /** @var int $tagPos */ foreach ($tagPositions as $tagPos) { if ($tagPos >= $iteratedPos) { $tagTokens[$tagPos] = $this->tokens[$tagPos] + [ 'contents' => $this->loadTagContentTokens($tagPos, $iteratedPos) ]; } } return $tagTokens; }
php
public function getTagTokens(): array { $iteratedPos = 0; $tagPositions = $this->getCommentStartToken()['comment_tags']; $tagTokens = []; /** @var int $tagPos */ foreach ($tagPositions as $tagPos) { if ($tagPos >= $iteratedPos) { $tagTokens[$tagPos] = $this->tokens[$tagPos] + [ 'contents' => $this->loadTagContentTokens($tagPos, $iteratedPos) ]; } } return $tagTokens; }
[ "public", "function", "getTagTokens", "(", ")", ":", "array", "{", "$", "iteratedPos", "=", "0", ";", "$", "tagPositions", "=", "$", "this", "->", "getCommentStartToken", "(", ")", "[", "'comment_tags'", "]", ";", "$", "tagTokens", "=", "[", "]", ";", ...
Returns array of all comment tag tokens. @return array List of all comment tag tokens indexed by token position
[ "Returns", "array", "of", "all", "comment", "tag", "tokens", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php#L103-L119
45,931
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php
DocTagHelper.getTagCounts
public function getTagCounts(array $tagTokens): array { $tagCounts = []; foreach ($tagTokens as $tagToken) { $tagName = $tagToken['content']; if (!array_key_exists($tagName, $tagCounts)) { $tagCounts[$tagName] = 0; } ++$tagCounts[$tagName]; } return $tagCounts; }
php
public function getTagCounts(array $tagTokens): array { $tagCounts = []; foreach ($tagTokens as $tagToken) { $tagName = $tagToken['content']; if (!array_key_exists($tagName, $tagCounts)) { $tagCounts[$tagName] = 0; } ++$tagCounts[$tagName]; } return $tagCounts; }
[ "public", "function", "getTagCounts", "(", "array", "$", "tagTokens", ")", ":", "array", "{", "$", "tagCounts", "=", "[", "]", ";", "foreach", "(", "$", "tagTokens", "as", "$", "tagToken", ")", "{", "$", "tagName", "=", "$", "tagToken", "[", "'content'...
Returns the individual count of every tag. @param array $tagTokens Array of tag tokens. @return array List of comment tags with there count of the current comment
[ "Returns", "the", "individual", "count", "of", "every", "tag", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php#L128-L143
45,932
mimmi20/BrowserDetector
src/Version/Helper/Safari.php
Safari.mapSafariVersion
public function mapSafariVersion(string $detectedVersion): string { $regularVersions = [ 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 4.3, 4.4, 5.0, 5.1, 5.2, 6.0, 6.1, 6.2, 7.0, 7.1, 8.0, 8.1, 9.0, 9.1, 10.0, 10.1, 11.0, 12.0, ]; if (in_array($detectedVersion, $regularVersions)) { return $detectedVersion; } $versions = [ '14600' => '12.0', '13600' => '11.0', '12600' => '10.0', '11600' => '9.1', '10500' => '8.0', '9500' => '7.0', '8500' => '6.0', '7500' => '5.1', '6500' => '5.0', '4500' => '4.0', '600' => '5.0', '500' => '4.0', '400' => '3.0', ]; foreach ($versions as $engineVersion => $osVersion) { if (version_compare($detectedVersion, (string) $engineVersion, '>=')) { return $osVersion; } } return '0'; }
php
public function mapSafariVersion(string $detectedVersion): string { $regularVersions = [ 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 4.3, 4.4, 5.0, 5.1, 5.2, 6.0, 6.1, 6.2, 7.0, 7.1, 8.0, 8.1, 9.0, 9.1, 10.0, 10.1, 11.0, 12.0, ]; if (in_array($detectedVersion, $regularVersions)) { return $detectedVersion; } $versions = [ '14600' => '12.0', '13600' => '11.0', '12600' => '10.0', '11600' => '9.1', '10500' => '8.0', '9500' => '7.0', '8500' => '6.0', '7500' => '5.1', '6500' => '5.0', '4500' => '4.0', '600' => '5.0', '500' => '4.0', '400' => '3.0', ]; foreach ($versions as $engineVersion => $osVersion) { if (version_compare($detectedVersion, (string) $engineVersion, '>=')) { return $osVersion; } } return '0'; }
[ "public", "function", "mapSafariVersion", "(", "string", "$", "detectedVersion", ")", ":", "string", "{", "$", "regularVersions", "=", "[", "3.0", ",", "3.1", ",", "3.2", ",", "4.0", ",", "4.1", ",", "4.2", ",", "4.3", ",", "4.4", ",", "5.0", ",", "5...
maps different Safari Versions to a normalized format @param string $detectedVersion @return string
[ "maps", "different", "Safari", "Versions", "to", "a", "normalized", "format" ]
1b90d994fcee01344a36bbe39afb14622bc8df9c
https://github.com/mimmi20/BrowserDetector/blob/1b90d994fcee01344a36bbe39afb14622bc8df9c/src/Version/Helper/Safari.php#L23-L79
45,933
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php
RequiredMethodTagsSniff.fixMinReturn
protected function fixMinReturn(int $stackPos): void { $closePos = $this->tokens[$stackPos]['comment_closer']; $closeTag = $this->tokens[$closePos]; $indent = str_repeat(' ', $closeTag['column'] - 1); $fileDecorator = $this->getFile(); $returnTypeHint = FunctionHelper::findReturnTypeHint( $fileDecorator->getBaseFile(), $fileDecorator->findNext([T_FUNCTION], $closePos + 1) ); $typeHint = $returnTypeHint ? $returnTypeHint->getTypeHint() : 'void'; $fixer = $fileDecorator->fixer; $fixer->beginChangeset(); $fixer->replaceToken( $closePos, "*\n{$indent}* @return {$typeHint}\n{$indent}{$closeTag['content']}" ); $fixer->endChangeset(); }
php
protected function fixMinReturn(int $stackPos): void { $closePos = $this->tokens[$stackPos]['comment_closer']; $closeTag = $this->tokens[$closePos]; $indent = str_repeat(' ', $closeTag['column'] - 1); $fileDecorator = $this->getFile(); $returnTypeHint = FunctionHelper::findReturnTypeHint( $fileDecorator->getBaseFile(), $fileDecorator->findNext([T_FUNCTION], $closePos + 1) ); $typeHint = $returnTypeHint ? $returnTypeHint->getTypeHint() : 'void'; $fixer = $fileDecorator->fixer; $fixer->beginChangeset(); $fixer->replaceToken( $closePos, "*\n{$indent}* @return {$typeHint}\n{$indent}{$closeTag['content']}" ); $fixer->endChangeset(); }
[ "protected", "function", "fixMinReturn", "(", "int", "$", "stackPos", ")", ":", "void", "{", "$", "closePos", "=", "$", "this", "->", "tokens", "[", "$", "stackPos", "]", "[", "'comment_closer'", "]", ";", "$", "closeTag", "=", "$", "this", "->", "toke...
Adds a return annotation if there is none. @param int $stackPos @return void
[ "Adds", "a", "return", "annotation", "if", "there", "is", "none", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php#L31-L55
45,934
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php
RequiredMethodTagsSniff.isMagicFunctionWithoutReturn
private function isMagicFunctionWithoutReturn(): bool { $whitelist = [ '__construct', '__destruct', '__clone', '__wakeup', '__set', '__unset', ]; $stackToken = $this->tokens[$this->stackPos]; $functionNamePtr = $this->file->getBaseFile()->findNext( [T_STRING], $this->stackPos + 1, $stackToken['parenthesis_opener'] ); $functionNameToken = $this->tokens[$functionNamePtr]; return in_array($functionNameToken['content'], $whitelist, true); }
php
private function isMagicFunctionWithoutReturn(): bool { $whitelist = [ '__construct', '__destruct', '__clone', '__wakeup', '__set', '__unset', ]; $stackToken = $this->tokens[$this->stackPos]; $functionNamePtr = $this->file->getBaseFile()->findNext( [T_STRING], $this->stackPos + 1, $stackToken['parenthesis_opener'] ); $functionNameToken = $this->tokens[$functionNamePtr]; return in_array($functionNameToken['content'], $whitelist, true); }
[ "private", "function", "isMagicFunctionWithoutReturn", "(", ")", ":", "bool", "{", "$", "whitelist", "=", "[", "'__construct'", ",", "'__destruct'", ",", "'__clone'", ",", "'__wakeup'", ",", "'__set'", ",", "'__unset'", ",", "]", ";", "$", "stackToken", "=", ...
Checks if the listener function is a magic php function without return. @return bool Indicator if the current function is not a whitelisted function
[ "Checks", "if", "the", "listener", "function", "is", "a", "magic", "php", "function", "without", "return", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php#L89-L111
45,935
furqansiddiqui/http-client
src/Authentication.php
Authentication.basic
public function basic(string $username, string $password) { $this->type = self::BASIC; $this->username = $username; $this->password = $password; }
php
public function basic(string $username, string $password) { $this->type = self::BASIC; $this->username = $username; $this->password = $password; }
[ "public", "function", "basic", "(", "string", "$", "username", ",", "string", "$", "password", ")", "{", "$", "this", "->", "type", "=", "self", "::", "BASIC", ";", "$", "this", "->", "username", "=", "$", "username", ";", "$", "this", "->", "passwor...
Basic HTTP authentication @param string $username @param string $password
[ "Basic", "HTTP", "authentication" ]
ecdb48f929829cd034070c481e113a31d339b87b
https://github.com/furqansiddiqui/http-client/blob/ecdb48f929829cd034070c481e113a31d339b87b/src/Authentication.php#L42-L47
45,936
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addError
public function addError( $error, $stackPtr, $code, $data = [], $severity = 0, $fixable = false ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addError( $error, $stackPtr, $code, $data = [], $severity = 0, $fixable = false ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addError", "(", "$", "error", ",", "$", "stackPtr", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ",", "$", "fixable", "=", "false", ")", "{", "return", "$", "this", "->", "__call", "(",...
Records an error against a specific token in the file. @param string $error The error message. @param int $stackPtr The stack position where the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the error message. @param int $severity The severity level for this error. A value of 0 will be converted into the default severity level. @param boolean $fixable Can the error be fixed by the sniff? @return boolean
[ "Records", "an", "error", "against", "a", "specific", "token", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L65-L74
45,937
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addErrorOnLine
public function addErrorOnLine( $error, $line, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addErrorOnLine( $error, $line, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addErrorOnLine", "(", "$", "error", ",", "$", "line", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_get_args"...
Records an error against a specific line in the file. @param string $error The error message. @param int $line The line on which the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the error message. @param int $severity The severity level for this error. A value of 0 will be converted into the default severity level. @return boolean
[ "Records", "an", "error", "against", "a", "specific", "line", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L88-L96
45,938
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addFixableError
public function addFixableError( $error, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addFixableError( $error, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addFixableError", "(", "$", "error", ",", "$", "stackPtr", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_get_...
Records a fixable error against a specific token in the file. Returns true if the error was recorded and should be fixed. @param string $error The error message. @param int $stackPtr The stack position where the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the error message. @param int $severity The severity level for this error. A value of 0 will be converted into the default severity level. @return boolean
[ "Records", "a", "fixable", "error", "against", "a", "specific", "token", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L112-L120
45,939
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addFixableWarning
public function addFixableWarning( $warning, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addFixableWarning( $warning, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addFixableWarning", "(", "$", "warning", ",", "$", "stackPtr", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_...
Records a fixable warning against a specific token in the file. Returns true if the warning was recorded and should be fixed. @param string $warning The error message. @param int $stackPtr The stack position where the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the warning message. @param int $severity The severity level for this warning. A value of 0 will be converted into the default severity level. @return boolean
[ "Records", "a", "fixable", "warning", "against", "a", "specific", "token", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L136-L144
45,940
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addMessage
protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable) { return $this->__call(__FUNCTION__, func_get_args()); }
php
protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "protected", "function", "addMessage", "(", "$", "error", ",", "$", "message", ",", "$", "line", ",", "$", "column", ",", "$", "code", ",", "$", "data", ",", "$", "severity", ",", "$", "fixable", ")", "{", "return", "$", "this", "->", "__call", "("...
Adds an error to the error stack. @param boolean $error Is this an error message? @param string $message The text of the message. @param int $line The line on which the message occurred. @param int $column The column at which the message occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the message. @param int $severity The severity level for this message. A value of 0 will be converted into the default severity level. @param boolean $fixable Can the problem be fixed by the sniff? @return boolean
[ "Adds", "an", "error", "to", "the", "error", "stack", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L161-L164
45,941
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.findFirstOnLine
public function findFirstOnLine($types, $start, $exclude = false, $value = null) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function findFirstOnLine($types, $start, $exclude = false, $value = null) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "findFirstOnLine", "(", "$", "types", ",", "$", "start", ",", "$", "exclude", "=", "false", ",", "$", "value", "=", "null", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_get_args", "(", ")", ")",...
Returns the position of the first token on a line, matching given type. Returns false if no token can be found. @param int|array $types The type(s) of tokens to search for. @param int $start The position to start searching from in the token stack. The first token matching on this line before this token will be returned. @param bool $exclude If true, find the token that is NOT of the types specified in $types. @param string $value The value that the token must be equal to. If value is omitted, tokens with any value will be returned. @return int | bool
[ "Returns", "the", "position", "of", "the", "first", "token", "on", "a", "line", "matching", "given", "type", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L277-L280
45,942
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.takeProperties
private function takeProperties(File $baseFile): void { $baseProps = get_object_vars($baseFile); array_walk($baseProps, function ($value, $key) { $this->$key = $value; }); }
php
private function takeProperties(File $baseFile): void { $baseProps = get_object_vars($baseFile); array_walk($baseProps, function ($value, $key) { $this->$key = $value; }); }
[ "private", "function", "takeProperties", "(", "File", "$", "baseFile", ")", ":", "void", "{", "$", "baseProps", "=", "get_object_vars", "(", "$", "baseFile", ")", ";", "array_walk", "(", "$", "baseProps", ",", "function", "(", "$", "value", ",", "$", "ke...
We need to clone the properties of the base file to this. A magic getter on inherited props does not work. @param File $baseFile @return void
[ "We", "need", "to", "clone", "the", "properties", "of", "the", "base", "file", "to", "this", ".", "A", "magic", "getter", "on", "inherited", "props", "does", "not", "work", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L761-L768
45,943
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php
LineHelper.removeLine
public function removeLine(int $line): void { foreach ($this->file->getTokens() as $tagPtr => $tagToken) { if ($tagToken['line'] !== $line) { continue; } $this->fixer->replaceToken($tagPtr, ''); if ($tagToken['line'] > $line) { break; } } }
php
public function removeLine(int $line): void { foreach ($this->file->getTokens() as $tagPtr => $tagToken) { if ($tagToken['line'] !== $line) { continue; } $this->fixer->replaceToken($tagPtr, ''); if ($tagToken['line'] > $line) { break; } } }
[ "public", "function", "removeLine", "(", "int", "$", "line", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "file", "->", "getTokens", "(", ")", "as", "$", "tagPtr", "=>", "$", "tagToken", ")", "{", "if", "(", "$", "tagToken", "[", "'lin...
Removes the given line. @param int $line The line which is to be removed @return void
[ "Removes", "the", "given", "line", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php#L57-L70
45,944
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php
LineHelper.removeLines
public function removeLines(int $startLine, int $endLine): void { for ($line = $startLine; $line <= $endLine; $line++) { $this->removeLine($line); } }
php
public function removeLines(int $startLine, int $endLine): void { for ($line = $startLine; $line <= $endLine; $line++) { $this->removeLine($line); } }
[ "public", "function", "removeLines", "(", "int", "$", "startLine", ",", "int", "$", "endLine", ")", ":", "void", "{", "for", "(", "$", "line", "=", "$", "startLine", ";", "$", "line", "<=", "$", "endLine", ";", "$", "line", "++", ")", "{", "$", "...
Removes lines by given start and end. @param int $startLine The first line which is to be removed @param int $endLine The last line which is to be removed @return void
[ "Removes", "lines", "by", "given", "start", "and", "end", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php#L80-L85
45,945
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Comparisons/EqualOperatorSniff.php
EqualOperatorSniff.replaceToken
private function replaceToken(): void { $file = $this->getFile(); $file->fixer->beginChangeset(); $file->fixer->replaceToken($this->getStackPos(), '==='); $file->fixer->endChangeset(); }
php
private function replaceToken(): void { $file = $this->getFile(); $file->fixer->beginChangeset(); $file->fixer->replaceToken($this->getStackPos(), '==='); $file->fixer->endChangeset(); }
[ "private", "function", "replaceToken", "(", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "file", "->", "fixer", "->", "beginChangeset", "(", ")", ";", "$", "file", "->", "fixer", "->", "replaceToken", "("...
Replace token with the T_IS_IDENTIAL token. @return void
[ "Replace", "token", "with", "the", "T_IS_IDENTIAL", "token", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Comparisons/EqualOperatorSniff.php#L88-L95
45,946
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php
ReturnTagSniff.checkForMissingDesc
private function checkForMissingDesc(string $type, array $returnParts): void { if (!in_array($type, $this->excludedTypes) && (count($returnParts) <= 1) && $this->descAsWarning) { throw (new CodeWarning( static::CODE_MISSING_RETURN_DESC, self::MESSAGE_MISSING_RETURN_DESC, $this->stackPos ))->setToken($this->token); } }
php
private function checkForMissingDesc(string $type, array $returnParts): void { if (!in_array($type, $this->excludedTypes) && (count($returnParts) <= 1) && $this->descAsWarning) { throw (new CodeWarning( static::CODE_MISSING_RETURN_DESC, self::MESSAGE_MISSING_RETURN_DESC, $this->stackPos ))->setToken($this->token); } }
[ "private", "function", "checkForMissingDesc", "(", "string", "$", "type", ",", "array", "$", "returnParts", ")", ":", "void", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "$", "this", "->", "excludedTypes", ")", "&&", "(", "count", "(", "$",...
Throws a code warning if you have no description. @throws CodeWarning @param string $type @param array $returnParts @return void
[ "Throws", "a", "code", "warning", "if", "you", "have", "no", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php#L67-L76
45,947
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php
ReturnTagSniff.checkForMixedType
private function checkForMixedType(string $type): self { if (strtolower($type) === 'mixed') { throw (new CodeWarning(static::CODE_MIXED_TYPE, self::MESSAGE_MIXED_TYPE, $this->stackPos)) ->setToken($this->token); } return $this; }
php
private function checkForMixedType(string $type): self { if (strtolower($type) === 'mixed') { throw (new CodeWarning(static::CODE_MIXED_TYPE, self::MESSAGE_MIXED_TYPE, $this->stackPos)) ->setToken($this->token); } return $this; }
[ "private", "function", "checkForMixedType", "(", "string", "$", "type", ")", ":", "self", "{", "if", "(", "strtolower", "(", "$", "type", ")", "===", "'mixed'", ")", "{", "throw", "(", "new", "CodeWarning", "(", "static", "::", "CODE_MIXED_TYPE", ",", "s...
Throws a warning if you declare a mixed type. @param string $type @throws CodeWarning @return $this
[ "Throws", "a", "warning", "if", "you", "declare", "a", "mixed", "type", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php#L86-L94
45,948
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocPosProviderTrait.php
DocPosProviderTrait.getDocCommentPos
protected function getDocCommentPos(): ?int { if ($this->docCommentPos === -1) { $this->docCommentPos = $this->loadDocCommentPos(); } return $this->docCommentPos; }
php
protected function getDocCommentPos(): ?int { if ($this->docCommentPos === -1) { $this->docCommentPos = $this->loadDocCommentPos(); } return $this->docCommentPos; }
[ "protected", "function", "getDocCommentPos", "(", ")", ":", "?", "int", "{", "if", "(", "$", "this", "->", "docCommentPos", "===", "-", "1", ")", "{", "$", "this", "->", "docCommentPos", "=", "$", "this", "->", "loadDocCommentPos", "(", ")", ";", "}", ...
Returns the position of the doc block if there is one. @return int|null
[ "Returns", "the", "position", "of", "the", "doc", "block", "if", "there", "is", "one", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocPosProviderTrait.php#L37-L44
45,949
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocPosProviderTrait.php
DocPosProviderTrait.getDocHelper
protected function getDocHelper(): DocHelper { if ($this->docHelper === null) { $this->docHelper = new DocHelper($this->getFile()->getBaseFile(), $this->getStackPos()); } return $this->docHelper; }
php
protected function getDocHelper(): DocHelper { if ($this->docHelper === null) { $this->docHelper = new DocHelper($this->getFile()->getBaseFile(), $this->getStackPos()); } return $this->docHelper; }
[ "protected", "function", "getDocHelper", "(", ")", ":", "DocHelper", "{", "if", "(", "$", "this", "->", "docHelper", "===", "null", ")", "{", "$", "this", "->", "docHelper", "=", "new", "DocHelper", "(", "$", "this", "->", "getFile", "(", ")", "->", ...
Returns the helper for the doc block. @return DocHelper
[ "Returns", "the", "helper", "for", "the", "doc", "block", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocPosProviderTrait.php#L51-L58
45,950
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocPosProviderTrait.php
DocPosProviderTrait.loadDocCommentPos
protected function loadDocCommentPos(): ?int { $docHelper = $this->getDocHelper(); return $docHelper->hasDocBlock() ? $docHelper->getBlockStartPosition() : null; }
php
protected function loadDocCommentPos(): ?int { $docHelper = $this->getDocHelper(); return $docHelper->hasDocBlock() ? $docHelper->getBlockStartPosition() : null; }
[ "protected", "function", "loadDocCommentPos", "(", ")", ":", "?", "int", "{", "$", "docHelper", "=", "$", "this", "->", "getDocHelper", "(", ")", ";", "return", "$", "docHelper", "->", "hasDocBlock", "(", ")", "?", "$", "docHelper", "->", "getBlockStartPos...
Loads the position of the doc comment. @return int|null
[ "Loads", "the", "position", "of", "the", "doc", "comment", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocPosProviderTrait.php#L79-L84
45,951
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/PackageTagSniff.php
PackageTagSniff.fixWrongPackage
private function fixWrongPackage(string $currentNamespace): void { $this->file->getFixer()->replaceToken( TokenHelper::findNext($this->file->getBaseFile(), [T_DOC_COMMENT_STRING], $this->stackPos), $currentNamespace ); }
php
private function fixWrongPackage(string $currentNamespace): void { $this->file->getFixer()->replaceToken( TokenHelper::findNext($this->file->getBaseFile(), [T_DOC_COMMENT_STRING], $this->stackPos), $currentNamespace ); }
[ "private", "function", "fixWrongPackage", "(", "string", "$", "currentNamespace", ")", ":", "void", "{", "$", "this", "->", "file", "->", "getFixer", "(", ")", "->", "replaceToken", "(", "TokenHelper", "::", "findNext", "(", "$", "this", "->", "file", "->"...
Fixes the wrong package and replaces it with the correct namespace. @param string $currentNamespace @return void
[ "Fixes", "the", "wrong", "package", "and", "replaces", "it", "with", "the", "correct", "namespace", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/PackageTagSniff.php#L37-L43
45,952
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php
DocHelper.getBlockEndPosition
public function getBlockEndPosition(): ?int { if ($this->blockEndPosition === false) { $this->blockEndPosition = $this->loadBlockEndPosition(); } return $this->blockEndPosition; }
php
public function getBlockEndPosition(): ?int { if ($this->blockEndPosition === false) { $this->blockEndPosition = $this->loadBlockEndPosition(); } return $this->blockEndPosition; }
[ "public", "function", "getBlockEndPosition", "(", ")", ":", "?", "int", "{", "if", "(", "$", "this", "->", "blockEndPosition", "===", "false", ")", "{", "$", "this", "->", "blockEndPosition", "=", "$", "this", "->", "loadBlockEndPosition", "(", ")", ";", ...
Returns position to the class comment end. @return int|null Position to the class comment end.
[ "Returns", "position", "to", "the", "class", "comment", "end", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L67-L74
45,953
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php
DocHelper.getBlockEndToken
public function getBlockEndToken(): array { if (!$this->hasDocBlock()) { throw new DomainException( sprintf('Missing doc block for position %s of file %s.', $this->stackPos, $this->file->getFilename()) ); } return $this->tokens[$this->getBlockEndPosition()]; }
php
public function getBlockEndToken(): array { if (!$this->hasDocBlock()) { throw new DomainException( sprintf('Missing doc block for position %s of file %s.', $this->stackPos, $this->file->getFilename()) ); } return $this->tokens[$this->getBlockEndPosition()]; }
[ "public", "function", "getBlockEndToken", "(", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "hasDocBlock", "(", ")", ")", "{", "throw", "new", "DomainException", "(", "sprintf", "(", "'Missing doc block for position %s of file %s.'", ",", "$", "t...
Returns token data of the evaluated class comment end. @return array Token data of the comment end.
[ "Returns", "token", "data", "of", "the", "evaluated", "class", "comment", "end", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L81-L90
45,954
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php
DocHelper.isMultiLine
public function isMultiLine(): bool { $openingToken = $this->getBlockStartToken(); $closingToken = $this->getBlockEndToken(); return $openingToken['line'] < $closingToken['line']; }
php
public function isMultiLine(): bool { $openingToken = $this->getBlockStartToken(); $closingToken = $this->getBlockEndToken(); return $openingToken['line'] < $closingToken['line']; }
[ "public", "function", "isMultiLine", "(", ")", ":", "bool", "{", "$", "openingToken", "=", "$", "this", "->", "getBlockStartToken", "(", ")", ";", "$", "closingToken", "=", "$", "this", "->", "getBlockEndToken", "(", ")", ";", "return", "$", "openingToken"...
Returns true if this doc block is a multi line comment. @return bool
[ "Returns", "true", "if", "this", "doc", "block", "is", "a", "multi", "line", "comment", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L131-L137
45,955
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php
DocHelper.loadBlockEndPosition
private function loadBlockEndPosition(): ?int { $endPos = $this->file->findPrevious( [T_DOC_COMMENT_CLOSE_TAG], $this->stackPos - 1, // Search till the next method, property, etc ... TokenHelper::findPreviousExcluding( $this->file, TokenHelper::$ineffectiveTokenCodes + Tokens::$methodPrefixes, $this->stackPos - 1 ) ); return ((int) $endPos) > 0 ? $endPos : null; }
php
private function loadBlockEndPosition(): ?int { $endPos = $this->file->findPrevious( [T_DOC_COMMENT_CLOSE_TAG], $this->stackPos - 1, // Search till the next method, property, etc ... TokenHelper::findPreviousExcluding( $this->file, TokenHelper::$ineffectiveTokenCodes + Tokens::$methodPrefixes, $this->stackPos - 1 ) ); return ((int) $endPos) > 0 ? $endPos : null; }
[ "private", "function", "loadBlockEndPosition", "(", ")", ":", "?", "int", "{", "$", "endPos", "=", "$", "this", "->", "file", "->", "findPrevious", "(", "[", "T_DOC_COMMENT_CLOSE_TAG", "]", ",", "$", "this", "->", "stackPos", "-", "1", ",", "// Search till...
Returns the position of the token for the doc block end. @return int|null
[ "Returns", "the", "position", "of", "the", "token", "for", "the", "doc", "block", "end", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L144-L158
45,956
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php
EmptyLinesDocSniff.removeUnnecessaryLines
private function removeUnnecessaryLines(File $phpcsFile, array $nextToken, array $currentToken): void { $movement = 2; if ($nextToken['code'] === T_DOC_COMMENT_CLOSE_TAG) { $movement = 1; } $phpcsFile->fixer->beginChangeset(); (new LineHelper($this->file))->removeLines( $currentToken['line'] + $movement, $nextToken['line'] - 1 ); $phpcsFile->fixer->endChangeset(); }
php
private function removeUnnecessaryLines(File $phpcsFile, array $nextToken, array $currentToken): void { $movement = 2; if ($nextToken['code'] === T_DOC_COMMENT_CLOSE_TAG) { $movement = 1; } $phpcsFile->fixer->beginChangeset(); (new LineHelper($this->file))->removeLines( $currentToken['line'] + $movement, $nextToken['line'] - 1 ); $phpcsFile->fixer->endChangeset(); }
[ "private", "function", "removeUnnecessaryLines", "(", "File", "$", "phpcsFile", ",", "array", "$", "nextToken", ",", "array", "$", "currentToken", ")", ":", "void", "{", "$", "movement", "=", "2", ";", "if", "(", "$", "nextToken", "[", "'code'", "]", "==...
Remove unnecessary lines from doc block. @param File $phpcsFile @param array $nextToken @param array $currentToken @return void
[ "Remove", "unnecessary", "lines", "from", "doc", "block", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php#L74-L90
45,957
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php
EmptyLinesDocSniff.searchEmptyLines
private function searchEmptyLines(File $phpcsFile, int $searchPosition): void { $endOfDoc = $phpcsFile->findEndOfStatement($searchPosition); do { $currentToken = $phpcsFile->getTokens()[$searchPosition]; $nextTokenPosition = (int) $phpcsFile->findNext( [T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR], $searchPosition + 1, $endOfDoc, true ); if ($hasToken = ($nextTokenPosition > 0)) { $nextToken = $phpcsFile->getTokens()[$nextTokenPosition]; $hasTooManyLines = ($nextToken['line'] - $currentToken['line']) > 2; if ($hasTooManyLines) { $isFixing = $phpcsFile->addFixableError( self::ERROR_EMPTY_LINES_FOUND, $nextTokenPosition, static::CODE_EMPTY_LINES_FOUND ); if ($isFixing) { $this->removeUnnecessaryLines($phpcsFile, $nextToken, $currentToken); } } $phpcsFile->recordMetric( $searchPosition, 'DocBlock has too many lines', $hasTooManyLines ? 'yes' : 'no' ); $searchPosition = $nextTokenPosition; } } while ($hasToken); }
php
private function searchEmptyLines(File $phpcsFile, int $searchPosition): void { $endOfDoc = $phpcsFile->findEndOfStatement($searchPosition); do { $currentToken = $phpcsFile->getTokens()[$searchPosition]; $nextTokenPosition = (int) $phpcsFile->findNext( [T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR], $searchPosition + 1, $endOfDoc, true ); if ($hasToken = ($nextTokenPosition > 0)) { $nextToken = $phpcsFile->getTokens()[$nextTokenPosition]; $hasTooManyLines = ($nextToken['line'] - $currentToken['line']) > 2; if ($hasTooManyLines) { $isFixing = $phpcsFile->addFixableError( self::ERROR_EMPTY_LINES_FOUND, $nextTokenPosition, static::CODE_EMPTY_LINES_FOUND ); if ($isFixing) { $this->removeUnnecessaryLines($phpcsFile, $nextToken, $currentToken); } } $phpcsFile->recordMetric( $searchPosition, 'DocBlock has too many lines', $hasTooManyLines ? 'yes' : 'no' ); $searchPosition = $nextTokenPosition; } } while ($hasToken); }
[ "private", "function", "searchEmptyLines", "(", "File", "$", "phpcsFile", ",", "int", "$", "searchPosition", ")", ":", "void", "{", "$", "endOfDoc", "=", "$", "phpcsFile", "->", "findEndOfStatement", "(", "$", "searchPosition", ")", ";", "do", "{", "$", "c...
Process method for tokens within scope and also outside scope. @param File $phpcsFile The sniffed file. @param int $searchPosition @return void
[ "Process", "method", "for", "tokens", "within", "scope", "and", "also", "outside", "scope", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php#L100-L138
45,958
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/SpaceAroundConcatSniff.php
SpaceAroundConcatSniff.fixDefaultProblem
protected function fixDefaultProblem(CodeWarning $warning): void { $newContent = ''; if (!$this->prevIsWhitespace) { $newContent = ' '; } $newContent .= '.'; if (!$this->nextIsWhitespace) { $newContent .= ' '; } $fixer = $this->getFile()->fixer; $fixer->beginChangeset(); $fixer->replaceToken($this->stackPos, $newContent); $fixer->endChangeset(); }
php
protected function fixDefaultProblem(CodeWarning $warning): void { $newContent = ''; if (!$this->prevIsWhitespace) { $newContent = ' '; } $newContent .= '.'; if (!$this->nextIsWhitespace) { $newContent .= ' '; } $fixer = $this->getFile()->fixer; $fixer->beginChangeset(); $fixer->replaceToken($this->stackPos, $newContent); $fixer->endChangeset(); }
[ "protected", "function", "fixDefaultProblem", "(", "CodeWarning", "$", "warning", ")", ":", "void", "{", "$", "newContent", "=", "''", ";", "if", "(", "!", "$", "this", "->", "prevIsWhitespace", ")", "{", "$", "newContent", "=", "' '", ";", "}", "$", "...
Adds whitespace around the concats. @param CodeWarning $warning @return void
[ "Adds", "whitespace", "around", "the", "concats", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/SpaceAroundConcatSniff.php#L56-L75
45,959
helsingborg-stad/Municipio
library/Theme/ColorScheme.php
ColorScheme.colorPickerDefaultPalette
public function colorPickerDefaultPalette() { if (!get_field('color_scheme', 'options')) { return; } if (!get_option($this->optionName) || !is_array(get_option($this->optionName)) || empty(get_option($this->optionName))) { $this->getRemoteColorScheme(get_field('color_scheme', 'options')); } $colors = (array) apply_filters( 'Municipio/Theme/ColorPickerDefaultPalette', get_option($this->optionName)); wp_localize_script( 'helsingborg-se-admin', 'themeColorPalette', [ 'colors' => $colors, ]); }
php
public function colorPickerDefaultPalette() { if (!get_field('color_scheme', 'options')) { return; } if (!get_option($this->optionName) || !is_array(get_option($this->optionName)) || empty(get_option($this->optionName))) { $this->getRemoteColorScheme(get_field('color_scheme', 'options')); } $colors = (array) apply_filters( 'Municipio/Theme/ColorPickerDefaultPalette', get_option($this->optionName)); wp_localize_script( 'helsingborg-se-admin', 'themeColorPalette', [ 'colors' => $colors, ]); }
[ "public", "function", "colorPickerDefaultPalette", "(", ")", "{", "if", "(", "!", "get_field", "(", "'color_scheme'", ",", "'options'", ")", ")", "{", "return", ";", "}", "if", "(", "!", "get_option", "(", "$", "this", "->", "optionName", ")", "||", "!",...
Localize theme colors to set color picker default colors @return void
[ "Localize", "theme", "colors", "to", "set", "color", "picker", "default", "colors" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L24-L39
45,960
helsingborg-stad/Municipio
library/Theme/ColorScheme.php
ColorScheme.getRemoteColorScheme
public function getRemoteColorScheme($manifestId = "") : bool { if (!defined('MUNICIPIO_STYLEGUIDE_URI')) { return false; } if (empty($manifestId)) { $manifestId = apply_filters('Municipio/theme/key', get_field('color_scheme', 'option')); } $args = (defined('DEV_MODE') && DEV_MODE == true) ? ['sslverify' => false] : array(); //Get remote data $request = wp_remote_get("https:" . MUNICIPIO_STYLEGUIDE_URI . "vars/" . $manifestId . '.json', $args); //Store if valid response if (wp_remote_retrieve_response_code($request) == 200) { if (!empty($response = json_decode(wp_remote_retrieve_body($request)))) { $this->storeColorScheme($response); } return true; } //Not updated return false; }
php
public function getRemoteColorScheme($manifestId = "") : bool { if (!defined('MUNICIPIO_STYLEGUIDE_URI')) { return false; } if (empty($manifestId)) { $manifestId = apply_filters('Municipio/theme/key', get_field('color_scheme', 'option')); } $args = (defined('DEV_MODE') && DEV_MODE == true) ? ['sslverify' => false] : array(); //Get remote data $request = wp_remote_get("https:" . MUNICIPIO_STYLEGUIDE_URI . "vars/" . $manifestId . '.json', $args); //Store if valid response if (wp_remote_retrieve_response_code($request) == 200) { if (!empty($response = json_decode(wp_remote_retrieve_body($request)))) { $this->storeColorScheme($response); } return true; } //Not updated return false; }
[ "public", "function", "getRemoteColorScheme", "(", "$", "manifestId", "=", "\"\"", ")", ":", "bool", "{", "if", "(", "!", "defined", "(", "'MUNICIPIO_STYLEGUIDE_URI'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "manifestId", ...
Get remote colorsheme from styleguide etc @param string $manifestId. A identifier that represents the id of the theme configuration (filename on server) @return bool
[ "Get", "remote", "colorsheme", "from", "styleguide", "etc" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L46-L72
45,961
helsingborg-stad/Municipio
library/Theme/ColorScheme.php
ColorScheme.storeColorScheme
public function storeColorScheme($colors) : bool { if (!is_array($colors) && !is_object($colors)) { $colors = array(); } return update_option($this->optionName, (array) $this->sanitizeColorSheme($colors), false); }
php
public function storeColorScheme($colors) : bool { if (!is_array($colors) && !is_object($colors)) { $colors = array(); } return update_option($this->optionName, (array) $this->sanitizeColorSheme($colors), false); }
[ "public", "function", "storeColorScheme", "(", "$", "colors", ")", ":", "bool", "{", "if", "(", "!", "is_array", "(", "$", "colors", ")", "&&", "!", "is_object", "(", "$", "colors", ")", ")", "{", "$", "colors", "=", "array", "(", ")", ";", "}", ...
Stores the colorsheme details in the database for use by other plugins @param string $colors. Contains a flat array of colors HEX to store. @return bool
[ "Stores", "the", "colorsheme", "details", "in", "the", "database", "for", "use", "by", "other", "plugins" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L80-L87
45,962
helsingborg-stad/Municipio
library/Theme/ColorScheme.php
ColorScheme.sanitizeColorSheme
public function sanitizeColorSheme($colors) { //Make array keyless $colors = array_values(array_unique((array) $colors)); //Check if value is valid HEX foreach ($colors as $colorKey => $color) { if (preg_match('/^#[a-f0-9]{6}$/i', $color)) { continue; } unset($colors[$colorKey]); } //Sort (base colors at the end) usort($colors, function ($a, $b) { return strlen($b)-strlen($a); }); return $colors; }
php
public function sanitizeColorSheme($colors) { //Make array keyless $colors = array_values(array_unique((array) $colors)); //Check if value is valid HEX foreach ($colors as $colorKey => $color) { if (preg_match('/^#[a-f0-9]{6}$/i', $color)) { continue; } unset($colors[$colorKey]); } //Sort (base colors at the end) usort($colors, function ($a, $b) { return strlen($b)-strlen($a); }); return $colors; }
[ "public", "function", "sanitizeColorSheme", "(", "$", "colors", ")", "{", "//Make array keyless", "$", "colors", "=", "array_values", "(", "array_unique", "(", "(", "array", ")", "$", "colors", ")", ")", ";", "//Check if value is valid HEX", "foreach", "(", "$",...
Remove duplicates etc and make the array stored keyless @param array/object $colors A unsanitized arry of colors (must be flat) @return array
[ "Remove", "duplicates", "etc", "and", "make", "the", "array", "stored", "keyless" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L105-L125
45,963
helsingborg-stad/Municipio
library/Helper/Html.php
Html.getHtmlTags
public static function getHtmlTags($content, $closeTags = true) { if ($closeTags == true) { $re = '@<[^>]*>@'; } else { $re = '@<[^>/]*>@'; } preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0); if (isset($matches) && !empty($matches)) { $tags = array(); foreach ($matches as $match) { $tags[] = $match[0]; } $tags = array_unique($tags); return $tags; } return; }
php
public static function getHtmlTags($content, $closeTags = true) { if ($closeTags == true) { $re = '@<[^>]*>@'; } else { $re = '@<[^>/]*>@'; } preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0); if (isset($matches) && !empty($matches)) { $tags = array(); foreach ($matches as $match) { $tags[] = $match[0]; } $tags = array_unique($tags); return $tags; } return; }
[ "public", "static", "function", "getHtmlTags", "(", "$", "content", ",", "$", "closeTags", "=", "true", ")", "{", "if", "(", "$", "closeTags", "==", "true", ")", "{", "$", "re", "=", "'@<[^>]*>@'", ";", "}", "else", "{", "$", "re", "=", "'@<[^>/]*>@'...
Get HTML Tags @param string $content String to get HTML tags from @param boolean $closeTags Set to false to exclude closing tags @return array Htmltags
[ "Get", "HTML", "Tags" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L13-L35
45,964
helsingborg-stad/Municipio
library/Helper/Html.php
Html.attributesToString
public static function attributesToString($attributesArray) { if (!is_array($attributesArray) || empty($attributesArray)) { return false; } $attributes = array(); foreach ($attributesArray as $attribute => $value) { if (!is_array($value) && !is_string($value) || !$value || empty($value)) { continue; } $values = (is_array($value)) ? implode(' ', array_unique($value)) : $value; $attributes[] = $attribute . '="' . $values . '"'; } return implode(' ', $attributes); }
php
public static function attributesToString($attributesArray) { if (!is_array($attributesArray) || empty($attributesArray)) { return false; } $attributes = array(); foreach ($attributesArray as $attribute => $value) { if (!is_array($value) && !is_string($value) || !$value || empty($value)) { continue; } $values = (is_array($value)) ? implode(' ', array_unique($value)) : $value; $attributes[] = $attribute . '="' . $values . '"'; } return implode(' ', $attributes); }
[ "public", "static", "function", "attributesToString", "(", "$", "attributesArray", ")", "{", "if", "(", "!", "is_array", "(", "$", "attributesArray", ")", "||", "empty", "(", "$", "attributesArray", ")", ")", "{", "return", "false", ";", "}", "$", "attribu...
Turn an array of HTML attributes into a string @param string $content String to get HTML attributes from @return array Attributes
[ "Turn", "an", "array", "of", "HTML", "attributes", "into", "a", "string" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L42-L60
45,965
helsingborg-stad/Municipio
library/Helper/Html.php
Html.getHtmlAttributes
public static function getHtmlAttributes($content) { $content = self::getHtmlTags($content, false); if (!is_array($content) || empty($content)) { return; } $content = implode($content); $re = '@(\s+)(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>]))+.)["\']?@'; preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0); $atts = array(); if ($matches) { foreach ($matches as $match) { $atts[$match[2]] = $match[0]; } return $atts; } return; }
php
public static function getHtmlAttributes($content) { $content = self::getHtmlTags($content, false); if (!is_array($content) || empty($content)) { return; } $content = implode($content); $re = '@(\s+)(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>]))+.)["\']?@'; preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0); $atts = array(); if ($matches) { foreach ($matches as $match) { $atts[$match[2]] = $match[0]; } return $atts; } return; }
[ "public", "static", "function", "getHtmlAttributes", "(", "$", "content", ")", "{", "$", "content", "=", "self", "::", "getHtmlTags", "(", "$", "content", ",", "false", ")", ";", "if", "(", "!", "is_array", "(", "$", "content", ")", "||", "empty", "(",...
Get HTML attributes from string @param string $content String to get HTML attributes from @return array Attributes
[ "Get", "HTML", "attributes", "from", "string" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L67-L91
45,966
helsingborg-stad/Municipio
library/Helper/Html.php
Html.stripTagsAndAtts
public static function stripTagsAndAtts($content, $allowedTags = '', $allowedAtts = '') { if (isset($allowedTags) && is_array($allowedTags)) { $content = strip_tags($content, implode($allowedTags)); } else { $content = strip_tags($content); } //Strip attributes $atts = \Municipio\Helper\Html::getHtmlAttributes($content); if ($atts && !empty($atts)) { if (isset($allowedAtts) && is_array($allowedAtts)) { foreach ($allowedAtts as $attribute) { unset($atts[$attribute]); } } foreach ($atts as $att) { $content = str_replace($att, "", $content); } } return $content; }
php
public static function stripTagsAndAtts($content, $allowedTags = '', $allowedAtts = '') { if (isset($allowedTags) && is_array($allowedTags)) { $content = strip_tags($content, implode($allowedTags)); } else { $content = strip_tags($content); } //Strip attributes $atts = \Municipio\Helper\Html::getHtmlAttributes($content); if ($atts && !empty($atts)) { if (isset($allowedAtts) && is_array($allowedAtts)) { foreach ($allowedAtts as $attribute) { unset($atts[$attribute]); } } foreach ($atts as $att) { $content = str_replace($att, "", $content); } } return $content; }
[ "public", "static", "function", "stripTagsAndAtts", "(", "$", "content", ",", "$", "allowedTags", "=", "''", ",", "$", "allowedAtts", "=", "''", ")", "{", "if", "(", "isset", "(", "$", "allowedTags", ")", "&&", "is_array", "(", "$", "allowedTags", ")", ...
Strip tags & attributes from String @param string $content String to get HTML attributes from @return array Attributes
[ "Strip", "tags", "&", "attributes", "from", "String" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L98-L122
45,967
helsingborg-stad/Municipio
library/Theme/Enqueue.php
Enqueue.adminStyle
public function adminStyle() { wp_register_style('helsingborg-se-admin', get_template_directory_uri(). '/assets/dist/' . \Municipio\Helper\CacheBust::name('css/admin.min.css')); wp_enqueue_style('helsingborg-se-admin'); wp_register_script('helsingborg-se-admin', get_template_directory_uri() . '/assets/dist/' . \Municipio\Helper\CacheBust::name('js/admin.js')); wp_enqueue_script('helsingborg-se-admin'); }
php
public function adminStyle() { wp_register_style('helsingborg-se-admin', get_template_directory_uri(). '/assets/dist/' . \Municipio\Helper\CacheBust::name('css/admin.min.css')); wp_enqueue_style('helsingborg-se-admin'); wp_register_script('helsingborg-se-admin', get_template_directory_uri() . '/assets/dist/' . \Municipio\Helper\CacheBust::name('js/admin.js')); wp_enqueue_script('helsingborg-se-admin'); }
[ "public", "function", "adminStyle", "(", ")", "{", "wp_register_style", "(", "'helsingborg-se-admin'", ",", "get_template_directory_uri", "(", ")", ".", "'/assets/dist/'", ".", "\\", "Municipio", "\\", "Helper", "\\", "CacheBust", "::", "name", "(", "'css/admin.min....
Enqueue admin style @return void
[ "Enqueue", "admin", "style" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Enqueue.php#L73-L80
45,968
helsingborg-stad/Municipio
library/Theme/Enqueue.php
Enqueue.waitForPrime
public function waitForPrime() { $wp_scripts = wp_scripts(); if (!is_admin() && isset($wp_scripts->registered)) { foreach ($wp_scripts->registered as $key => $item) { if (is_array($item->deps) && !empty($item->deps)) { foreach ($item->deps as $depkey => $depencency) { $item->deps[$depkey] = str_replace("jquery", $this->defaultPrimeName, strtolower($depencency)); } } } } }
php
public function waitForPrime() { $wp_scripts = wp_scripts(); if (!is_admin() && isset($wp_scripts->registered)) { foreach ($wp_scripts->registered as $key => $item) { if (is_array($item->deps) && !empty($item->deps)) { foreach ($item->deps as $depkey => $depencency) { $item->deps[$depkey] = str_replace("jquery", $this->defaultPrimeName, strtolower($depencency)); } } } } }
[ "public", "function", "waitForPrime", "(", ")", "{", "$", "wp_scripts", "=", "wp_scripts", "(", ")", ";", "if", "(", "!", "is_admin", "(", ")", "&&", "isset", "(", "$", "wp_scripts", "->", "registered", ")", ")", "{", "foreach", "(", "$", "wp_scripts",...
Change jquery deps to hbgprime deps @return void
[ "Change", "jquery", "deps", "to", "hbgprime", "deps" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Enqueue.php#L263-L276
45,969
helsingborg-stad/Municipio
library/Helper/Styleguide.php
Styleguide._getBaseUri
private static function _getBaseUri() { if (defined('MUNICIPIO_STYLEGUIDE_URI') && MUNICIPIO_STYLEGUIDE_URI != "") { $uri = MUNICIPIO_STYLEGUIDE_URI; } else { $uri = self::$_uri; } $uri = rtrim(apply_filters('Municipio/theme/styleguide_uri', $uri), '/'); if (defined('STYLEGUIDE_VERSION') && STYLEGUIDE_VERSION != "") { $uri .= '/' . STYLEGUIDE_VERSION; } return $uri; }
php
private static function _getBaseUri() { if (defined('MUNICIPIO_STYLEGUIDE_URI') && MUNICIPIO_STYLEGUIDE_URI != "") { $uri = MUNICIPIO_STYLEGUIDE_URI; } else { $uri = self::$_uri; } $uri = rtrim(apply_filters('Municipio/theme/styleguide_uri', $uri), '/'); if (defined('STYLEGUIDE_VERSION') && STYLEGUIDE_VERSION != "") { $uri .= '/' . STYLEGUIDE_VERSION; } return $uri; }
[ "private", "static", "function", "_getBaseUri", "(", ")", "{", "if", "(", "defined", "(", "'MUNICIPIO_STYLEGUIDE_URI'", ")", "&&", "MUNICIPIO_STYLEGUIDE_URI", "!=", "\"\"", ")", "{", "$", "uri", "=", "MUNICIPIO_STYLEGUIDE_URI", ";", "}", "else", "{", "$", "uri...
Returns the base URI of the styleguide. @return string
[ "Returns", "the", "base", "URI", "of", "the", "styleguide", "." ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Styleguide.php#L27-L42
45,970
helsingborg-stad/Municipio
library/Helper/Styleguide.php
Styleguide.getStylePath
public static function getStylePath($isBem = false) { $directory = $isBem ? 'css-bem' : 'css'; $extension = self::_isDevMode() ? 'dev' : 'min'; $theme = self::_getTheme(); return self::getPath($directory . "/". "hbg-prime-" . $theme . "." . $extension . ".css"); }
php
public static function getStylePath($isBem = false) { $directory = $isBem ? 'css-bem' : 'css'; $extension = self::_isDevMode() ? 'dev' : 'min'; $theme = self::_getTheme(); return self::getPath($directory . "/". "hbg-prime-" . $theme . "." . $extension . ".css"); }
[ "public", "static", "function", "getStylePath", "(", "$", "isBem", "=", "false", ")", "{", "$", "directory", "=", "$", "isBem", "?", "'css-bem'", ":", "'css'", ";", "$", "extension", "=", "self", "::", "_isDevMode", "(", ")", "?", "'dev'", ":", "'min'"...
Returns the complete style path. @param bool $isBem Set to get a BEM theme. @return string
[ "Returns", "the", "complete", "style", "path", "." ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Styleguide.php#L79-L86
45,971
helsingborg-stad/Municipio
library/Admin/TinyMce/PluginClass.php
PluginClass.setupTinymcePlugin
public function setupTinymcePlugin() { if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) { return; } // Check if the logged in WordPress User has the Visual Editor enabled // If not, don't register our TinyMCE plugin if (get_user_option('rich_editing') !== 'true') { return; } $this->init(); if (!$this->pluginSlug || !$this->pluginSlug) { return; } //Change button row placement if buttonRow is defined if (isset($this->buttonRow) && is_numeric($this->buttonRow) && $this->buttonRow > 1) { $this->buttonFilter .= '_' . $this->buttonRow; } //LocalizeData (if any) if (is_array($this->data) && !empty($this->data)) { add_action('admin_head', array($this, 'localizeScript')); } add_filter('mce_external_plugins', array($this, 'addTinyMcePlugin')); add_filter($this->buttonFilter, array($this, 'addTinymceToolbarButton' )); }
php
public function setupTinymcePlugin() { if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) { return; } // Check if the logged in WordPress User has the Visual Editor enabled // If not, don't register our TinyMCE plugin if (get_user_option('rich_editing') !== 'true') { return; } $this->init(); if (!$this->pluginSlug || !$this->pluginSlug) { return; } //Change button row placement if buttonRow is defined if (isset($this->buttonRow) && is_numeric($this->buttonRow) && $this->buttonRow > 1) { $this->buttonFilter .= '_' . $this->buttonRow; } //LocalizeData (if any) if (is_array($this->data) && !empty($this->data)) { add_action('admin_head', array($this, 'localizeScript')); } add_filter('mce_external_plugins', array($this, 'addTinyMcePlugin')); add_filter($this->buttonFilter, array($this, 'addTinymceToolbarButton' )); }
[ "public", "function", "setupTinymcePlugin", "(", ")", "{", "if", "(", "!", "current_user_can", "(", "'edit_posts'", ")", "&&", "!", "current_user_can", "(", "'edit_pages'", ")", ")", "{", "return", ";", "}", "// Check if the logged in WordPress User has the Visual Edi...
Check if the current user can edit Posts or Pages, and is using the Visual Editor If so, add some filters so we can register our plugin
[ "Check", "if", "the", "current", "user", "can", "edit", "Posts", "or", "Pages", "and", "is", "using", "the", "Visual", "Editor", "If", "so", "add", "some", "filters", "so", "we", "can", "register", "our", "plugin" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/TinyMce/PluginClass.php#L46-L76
45,972
helsingborg-stad/Municipio
library/Search/General.php
General.searchAttachmentPermalink
public function searchAttachmentPermalink($permalink, $post) { if (isset($post->post_type) && $post->post_type == 'attachment') { return wp_get_attachment_url($post->ID); } else { return $permalink; } }
php
public function searchAttachmentPermalink($permalink, $post) { if (isset($post->post_type) && $post->post_type == 'attachment') { return wp_get_attachment_url($post->ID); } else { return $permalink; } }
[ "public", "function", "searchAttachmentPermalink", "(", "$", "permalink", ",", "$", "post", ")", "{", "if", "(", "isset", "(", "$", "post", "->", "post_type", ")", "&&", "$", "post", "->", "post_type", "==", "'attachment'", ")", "{", "return", "wp_get_atta...
Get attachment permalink for search result @param string $permalink @param WP_Post $post @return string Url
[ "Get", "attachment", "permalink", "for", "search", "result" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/General.php#L19-L26
45,973
helsingborg-stad/Municipio
library/Helper/Ajax.php
Ajax.localize
public function localize($var, $handle = null) { if(! isset($this->data) || ! $this->data || is_string($var) == false) { return false; } if($handle !== null) { $this->handle = $handle; } $this->var = $var; add_action( 'wp_enqueue_scripts', array($this, '_localize') ); return true; }
php
public function localize($var, $handle = null) { if(! isset($this->data) || ! $this->data || is_string($var) == false) { return false; } if($handle !== null) { $this->handle = $handle; } $this->var = $var; add_action( 'wp_enqueue_scripts', array($this, '_localize') ); return true; }
[ "public", "function", "localize", "(", "$", "var", ",", "$", "handle", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", ")", "||", "!", "$", "this", "->", "data", "||", "is_string", "(", "$", "var", ")", "==", "fa...
Localize - Pass data from PHP to JS @param $var - Define variable name used in JS file @param $handle - Specify script handle (optional) @return boolean
[ "Localize", "-", "Pass", "data", "from", "PHP", "to", "JS" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Ajax.php#L19-L34
45,974
helsingborg-stad/Municipio
library/Helper/Ajax.php
Ajax.hook
public function hook($functionName, $private = true) { if(! method_exists($this, $functionName) || is_bool($private) == false) { return false; } switch ($private) { case false: add_action( 'wp_ajax_nopriv_'.$functionName, array($this,$functionName) ); break; default: add_action( 'wp_ajax_'.$functionName, array($this,$functionName) ); break; } add_action( 'wp_ajax_'.$functionName, array($this,$functionName) ); return true; }
php
public function hook($functionName, $private = true) { if(! method_exists($this, $functionName) || is_bool($private) == false) { return false; } switch ($private) { case false: add_action( 'wp_ajax_nopriv_'.$functionName, array($this,$functionName) ); break; default: add_action( 'wp_ajax_'.$functionName, array($this,$functionName) ); break; } add_action( 'wp_ajax_'.$functionName, array($this,$functionName) ); return true; }
[ "public", "function", "hook", "(", "$", "functionName", ",", "$", "private", "=", "true", ")", "{", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "functionName", ")", "||", "is_bool", "(", "$", "private", ")", "==", "false", ")", "{", ...
Hook - Hook function to WP ajax @param string $functionName - Name of existing function within the class @param boolean $private - Hook fires only for logged-in users, set to false for to fire for everyone @return boolean
[ "Hook", "-", "Hook", "function", "to", "WP", "ajax" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Ajax.php#L47-L67
45,975
helsingborg-stad/Municipio
library/Content/CustomTaxonomy.php
CustomTaxonomy.populatePostTypeSelect
public function populatePostTypeSelect($field) { $choices = array_map('trim', get_post_types()); $choices = array_diff($choices, array('revision','acf-field-group','acf-field','nav_menu_item')); if (is_array($choices)) { foreach ($choices as $choice) { $field['choices'][ $choice ] = $choice; } } return $field; }
php
public function populatePostTypeSelect($field) { $choices = array_map('trim', get_post_types()); $choices = array_diff($choices, array('revision','acf-field-group','acf-field','nav_menu_item')); if (is_array($choices)) { foreach ($choices as $choice) { $field['choices'][ $choice ] = $choice; } } return $field; }
[ "public", "function", "populatePostTypeSelect", "(", "$", "field", ")", "{", "$", "choices", "=", "array_map", "(", "'trim'", ",", "get_post_types", "(", ")", ")", ";", "$", "choices", "=", "array_diff", "(", "$", "choices", ",", "array", "(", "'revision'"...
Adds value to acf post type filed @param array $field Acf field @return void
[ "Adds", "value", "to", "acf", "post", "type", "filed" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/CustomTaxonomy.php#L76-L89
45,976
helsingborg-stad/Municipio
library/Template.php
Template.initCustomTemplates
public function initCustomTemplates() { $directory = MUNICIPIO_PATH . 'library/Controller/'; foreach (@glob($directory . "*.php") as $file) { $class = '\Municipio\Controller\\' . basename($file, '.php'); if (!class_exists($class)) { continue; } if (!method_exists($class, 'registerTemplate')) { continue; } $class::registerTemplate(); unset($class); } }
php
public function initCustomTemplates() { $directory = MUNICIPIO_PATH . 'library/Controller/'; foreach (@glob($directory . "*.php") as $file) { $class = '\Municipio\Controller\\' . basename($file, '.php'); if (!class_exists($class)) { continue; } if (!method_exists($class, 'registerTemplate')) { continue; } $class::registerTemplate(); unset($class); } }
[ "public", "function", "initCustomTemplates", "(", ")", "{", "$", "directory", "=", "MUNICIPIO_PATH", ".", "'library/Controller/'", ";", "foreach", "(", "@", "glob", "(", "$", "directory", ".", "\"*.php\"", ")", "as", "$", "file", ")", "{", "$", "class", "=...
Initializes custom templates @return void
[ "Initializes", "custom", "templates" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L75-L93
45,977
helsingborg-stad/Municipio
library/Template.php
Template.getSearchForm
public function getSearchForm($searchform) { if ($view = \Municipio\Helper\Template::locateTemplate('searchform.blade.php')) { $view = $this->cleanViewPath($view); $this->loadController($view); $this->render($view); return false; } return $searchform; }
php
public function getSearchForm($searchform) { if ($view = \Municipio\Helper\Template::locateTemplate('searchform.blade.php')) { $view = $this->cleanViewPath($view); $this->loadController($view); $this->render($view); return false; } return $searchform; }
[ "public", "function", "getSearchForm", "(", "$", "searchform", ")", "{", "if", "(", "$", "view", "=", "\\", "Municipio", "\\", "Helper", "\\", "Template", "::", "locateTemplate", "(", "'searchform.blade.php'", ")", ")", "{", "$", "view", "=", "$", "this", ...
Get searchform template @param string $searchform Original markup @return mixed
[ "Get", "searchform", "template" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L100-L110
45,978
helsingborg-stad/Municipio
library/Template.php
Template.load
public function load($template) { if ((is_page() || is_single() || is_front_page()) && !empty(get_page_template_slug()) && get_page_template_slug() != $template) { if (\Municipio\Helper\Template::locateTemplate(get_page_template_slug())) { $template = get_page_template_slug(); } } if (!\Municipio\Helper\Template::isBlade($template)) { $path = $template; // Return path if file exists, else default to page.blade.php if (file_exists($path)) { return $path; } else { if (current_user_can('administrator')) { \Municipio\Helper\Notice::add('<strong>' . __('Admin notice', 'municipio') . ':</strong> ' . sprintf(__('View [%s] was not found. Defaulting to [page.blade.php].', 'municipio'), $template), 'warning', 'pricon pricon-notice-warning'); } $template = \Municipio\Helper\Template::locateTemplate('views/page.blade.php'); } } // Clean the view path $view = $this->cleanViewPath($template); // Load view controller $controller = $this->loadController($view); // Render the view $data = null; if ($controller) { $data = $controller->getData(); } $this->render($view, $data); return false; }
php
public function load($template) { if ((is_page() || is_single() || is_front_page()) && !empty(get_page_template_slug()) && get_page_template_slug() != $template) { if (\Municipio\Helper\Template::locateTemplate(get_page_template_slug())) { $template = get_page_template_slug(); } } if (!\Municipio\Helper\Template::isBlade($template)) { $path = $template; // Return path if file exists, else default to page.blade.php if (file_exists($path)) { return $path; } else { if (current_user_can('administrator')) { \Municipio\Helper\Notice::add('<strong>' . __('Admin notice', 'municipio') . ':</strong> ' . sprintf(__('View [%s] was not found. Defaulting to [page.blade.php].', 'municipio'), $template), 'warning', 'pricon pricon-notice-warning'); } $template = \Municipio\Helper\Template::locateTemplate('views/page.blade.php'); } } // Clean the view path $view = $this->cleanViewPath($template); // Load view controller $controller = $this->loadController($view); // Render the view $data = null; if ($controller) { $data = $controller->getData(); } $this->render($view, $data); return false; }
[ "public", "function", "load", "(", "$", "template", ")", "{", "if", "(", "(", "is_page", "(", ")", "||", "is_single", "(", ")", "||", "is_front_page", "(", ")", ")", "&&", "!", "empty", "(", "get_page_template_slug", "(", ")", ")", "&&", "get_page_temp...
Load controller and view @param string $template Template @return mixed Exception or false, false to make sure no standard template file from wordpres is beeing included
[ "Load", "controller", "and", "view" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L118-L156
45,979
helsingborg-stad/Municipio
library/Template.php
Template.loadController
public function loadController($template) { $template = basename($template) . '.php'; do_action('Municipio/blade/before_load_controller'); if (basename($template) == '404.php') { $template = 'e404.php'; } switch ($template) { case 'author.php': if (!defined('MUNICIPIO_BLOCK_AUTHOR_PAGES') || MUNICIPIO_BLOCK_AUTHOR_PAGES) { $template = 'archive.php'; } break; } $controller = \Municipio\Helper\Controller::locateController($template); if (!$controller) { $controller = \Municipio\Helper\Controller::locateController('BaseController'); } $controller = apply_filters('Municipio/blade/controller', $controller); require_once $controller; $namespace = \Municipio\Helper\Controller::getNamespace($controller); $class = '\\' . $namespace . '\\' . basename($controller, '.php'); do_action('Municipio/blade/after_load_controller'); return new $class(); }
php
public function loadController($template) { $template = basename($template) . '.php'; do_action('Municipio/blade/before_load_controller'); if (basename($template) == '404.php') { $template = 'e404.php'; } switch ($template) { case 'author.php': if (!defined('MUNICIPIO_BLOCK_AUTHOR_PAGES') || MUNICIPIO_BLOCK_AUTHOR_PAGES) { $template = 'archive.php'; } break; } $controller = \Municipio\Helper\Controller::locateController($template); if (!$controller) { $controller = \Municipio\Helper\Controller::locateController('BaseController'); } $controller = apply_filters('Municipio/blade/controller', $controller); require_once $controller; $namespace = \Municipio\Helper\Controller::getNamespace($controller); $class = '\\' . $namespace . '\\' . basename($controller, '.php'); do_action('Municipio/blade/after_load_controller'); return new $class(); }
[ "public", "function", "loadController", "(", "$", "template", ")", "{", "$", "template", "=", "basename", "(", "$", "template", ")", ".", "'.php'", ";", "do_action", "(", "'Municipio/blade/before_load_controller'", ")", ";", "if", "(", "basename", "(", "$", ...
Loads controller for view template @param string $template Path to template @return bool True if controller loaded, else false
[ "Loads", "controller", "for", "view", "template" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L163-L196
45,980
helsingborg-stad/Municipio
library/Comment/CommentsFilters.php
CommentsFilters.stripTags
public function stripTags($comment_text, $comment) { $allowedTags = array( "<h1>", "<h2>", "<h3>", "<h4>", "<strong>","<b>", "<br>", "<hr>", "<em>", "<ol>","<ul>","<li>", "<p>", "<span>", "<a>", "<img>", "<del>", "<ins>", "<blockquote>" ); $allowedAttributes = array('href', 'class', 'rel', 'id', 'src'); return \Municipio\Helper\Html::stripTagsAndAtts($comment_text, $allowedTags, $allowedAttributes); }
php
public function stripTags($comment_text, $comment) { $allowedTags = array( "<h1>", "<h2>", "<h3>", "<h4>", "<strong>","<b>", "<br>", "<hr>", "<em>", "<ol>","<ul>","<li>", "<p>", "<span>", "<a>", "<img>", "<del>", "<ins>", "<blockquote>" ); $allowedAttributes = array('href', 'class', 'rel', 'id', 'src'); return \Municipio\Helper\Html::stripTagsAndAtts($comment_text, $allowedTags, $allowedAttributes); }
[ "public", "function", "stripTags", "(", "$", "comment_text", ",", "$", "comment", ")", "{", "$", "allowedTags", "=", "array", "(", "\"<h1>\"", ",", "\"<h2>\"", ",", "\"<h3>\"", ",", "\"<h4>\"", ",", "\"<strong>\"", ",", "\"<b>\"", ",", "\"<br>\"", ",", "\"...
Strip html from comment
[ "Strip", "html", "from", "comment" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsFilters.php#L17-L33
45,981
helsingborg-stad/Municipio
library/Comment/CommentsFilters.php
CommentsFilters.validateReCaptcha
public function validateReCaptcha() { if (is_user_logged_in()) { return; } $response = isset($_POST['g-recaptcha-response']) ? esc_attr($_POST['g-recaptcha-response']) : ''; $reCaptcha = \Municipio\Helper\ReCaptcha::controlReCaptcha($response); if (!$reCaptcha) { wp_die(sprintf('<strong>%s</strong>:&nbsp;%s', __('Error', 'municipio'), __('reCaptcha verification failed', 'municipio'))); } return; }
php
public function validateReCaptcha() { if (is_user_logged_in()) { return; } $response = isset($_POST['g-recaptcha-response']) ? esc_attr($_POST['g-recaptcha-response']) : ''; $reCaptcha = \Municipio\Helper\ReCaptcha::controlReCaptcha($response); if (!$reCaptcha) { wp_die(sprintf('<strong>%s</strong>:&nbsp;%s', __('Error', 'municipio'), __('reCaptcha verification failed', 'municipio'))); } return; }
[ "public", "function", "validateReCaptcha", "(", ")", "{", "if", "(", "is_user_logged_in", "(", ")", ")", "{", "return", ";", "}", "$", "response", "=", "isset", "(", "$", "_POST", "[", "'g-recaptcha-response'", "]", ")", "?", "esc_attr", "(", "$", "_POST...
Check reCaptcha before comment is saved to post @return void
[ "Check", "reCaptcha", "before", "comment", "is", "saved", "to", "post" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsFilters.php#L52-L66
45,982
helsingborg-stad/Municipio
library/Controller/BaseController.php
BaseController.layout
public function layout() { $this->data['layout']['content'] = 'grid-xs-12 order-xs-1 order-md-2'; $this->data['layout']['sidebarLeft'] = 'grid-xs-12 grid-md-4 grid-lg-3 order-xs-2 order-md-1'; $this->data['layout']['sidebarRight'] = 'grid-xs-12 grid-md-4 grid-lg-3 hidden-xs hidden-sm hidden-md order-md-3'; $sidebarLeft = false; $sidebarRight = false; if (get_field('archive_' . sanitize_title(get_post_type()) . '_show_sidebar_navigation', 'option') && is_post_type_archive(get_post_type())) { $sidebarLeft = true; } //Has child or is parent and nav_sub is enabled if (get_field('nav_sub_enable', 'option') && is_singular() && !empty(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A)) || get_field('nav_sub_enable', 'option') && is_singular() && count(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A)) > 0) { $sidebarLeft = true; } if (is_active_sidebar('left-sidebar') || is_active_sidebar('left-sidebar-bottom')) { $sidebarLeft = true; } if (is_active_sidebar('right-sidebar')) { $sidebarRight = true; } if ($sidebarLeft && $sidebarRight) { $this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-6 order-xs-1 order-md-2'; } elseif ($sidebarLeft || $sidebarRight) { $this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-9 order-xs-1 order-md-2'; } if (!$sidebarLeft && $sidebarRight) { $this->data['layout']['sidebarLeft'] .= ' hidden-lg'; } if (is_front_page()) { $this->data['layout']['content'] = 'grid-xs-12'; } $this->data['layout'] = apply_filters('Municipio/Controller/BaseController/Layout', $this->data['layout'], $sidebarLeft, $sidebarRight); }
php
public function layout() { $this->data['layout']['content'] = 'grid-xs-12 order-xs-1 order-md-2'; $this->data['layout']['sidebarLeft'] = 'grid-xs-12 grid-md-4 grid-lg-3 order-xs-2 order-md-1'; $this->data['layout']['sidebarRight'] = 'grid-xs-12 grid-md-4 grid-lg-3 hidden-xs hidden-sm hidden-md order-md-3'; $sidebarLeft = false; $sidebarRight = false; if (get_field('archive_' . sanitize_title(get_post_type()) . '_show_sidebar_navigation', 'option') && is_post_type_archive(get_post_type())) { $sidebarLeft = true; } //Has child or is parent and nav_sub is enabled if (get_field('nav_sub_enable', 'option') && is_singular() && !empty(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A)) || get_field('nav_sub_enable', 'option') && is_singular() && count(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A)) > 0) { $sidebarLeft = true; } if (is_active_sidebar('left-sidebar') || is_active_sidebar('left-sidebar-bottom')) { $sidebarLeft = true; } if (is_active_sidebar('right-sidebar')) { $sidebarRight = true; } if ($sidebarLeft && $sidebarRight) { $this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-6 order-xs-1 order-md-2'; } elseif ($sidebarLeft || $sidebarRight) { $this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-9 order-xs-1 order-md-2'; } if (!$sidebarLeft && $sidebarRight) { $this->data['layout']['sidebarLeft'] .= ' hidden-lg'; } if (is_front_page()) { $this->data['layout']['content'] = 'grid-xs-12'; } $this->data['layout'] = apply_filters('Municipio/Controller/BaseController/Layout', $this->data['layout'], $sidebarLeft, $sidebarRight); }
[ "public", "function", "layout", "(", ")", "{", "$", "this", "->", "data", "[", "'layout'", "]", "[", "'content'", "]", "=", "'grid-xs-12 order-xs-1 order-md-2'", ";", "$", "this", "->", "data", "[", "'layout'", "]", "[", "'sidebarLeft'", "]", "=", "'grid-x...
Set main layout columns @return void
[ "Set", "main", "layout", "columns" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L71-L115
45,983
helsingborg-stad/Municipio
library/Controller/BaseController.php
BaseController.getSocialShareUrl
public function getSocialShareUrl() { //Get the post id if(!$postId = get_the_ID()) { global $post; $postId = $post->ID; } //Return share url return urlencode(get_home_url(null, '?socialShareId=' . $postId, null)); }
php
public function getSocialShareUrl() { //Get the post id if(!$postId = get_the_ID()) { global $post; $postId = $post->ID; } //Return share url return urlencode(get_home_url(null, '?socialShareId=' . $postId, null)); }
[ "public", "function", "getSocialShareUrl", "(", ")", "{", "//Get the post id", "if", "(", "!", "$", "postId", "=", "get_the_ID", "(", ")", ")", "{", "global", "$", "post", ";", "$", "postId", "=", "$", "post", "->", "ID", ";", "}", "//Return share url", ...
Get the social share url @return string
[ "Get", "the", "social", "share", "url" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L154-L164
45,984
helsingborg-stad/Municipio
library/Controller/BaseController.php
BaseController.customizerHeader
public function customizerHeader() { if (get_field('header_layout', 'options') !== 'customizer') { return; } $customizerHeader = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__header_sections', 'options', 'id'); $this->data['headerLayout']['classes'] = 's-site-header'; $this->data['headerLayout']['template'] = 'customizer'; if ($customizerHeader->hasItems) { foreach ($customizerHeader->repeater as $headerData) { $this->data['headerLayout']['headers'][] = new \Municipio\Customizer\Header($headerData); } } }
php
public function customizerHeader() { if (get_field('header_layout', 'options') !== 'customizer') { return; } $customizerHeader = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__header_sections', 'options', 'id'); $this->data['headerLayout']['classes'] = 's-site-header'; $this->data['headerLayout']['template'] = 'customizer'; if ($customizerHeader->hasItems) { foreach ($customizerHeader->repeater as $headerData) { $this->data['headerLayout']['headers'][] = new \Municipio\Customizer\Header($headerData); } } }
[ "public", "function", "customizerHeader", "(", ")", "{", "if", "(", "get_field", "(", "'header_layout'", ",", "'options'", ")", "!==", "'customizer'", ")", "{", "return", ";", "}", "$", "customizerHeader", "=", "new", "\\", "Municipio", "\\", "Customizer", "...
Sends necessary data to the view for customizer header @return void
[ "Sends", "necessary", "data", "to", "the", "view", "for", "customizer", "header" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L179-L194
45,985
helsingborg-stad/Municipio
library/Controller/BaseController.php
BaseController.customizerFooter
public function customizerFooter() { if (get_field('footer_layout', 'options') !== 'customizer') { return; } $customizerFooter = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__footer_sections', 'options', 'id'); $classes = array(); $classes[] = 's-site-footer'; $classes[] = 'hidden-print'; $classes[] = (get_field('scroll_elevator_enabled', 'option')) ? 'scroll-elevator-toggle' : ''; $this->data['footerLayout']['template'] = 'customizer'; $this->data['footerLayout']['classes'] = implode(' ', $classes); if ($customizerFooter->hasItems) { foreach ($customizerFooter->repeater as $footerData) { $this->data['footerSections'][] = new \Municipio\Customizer\Footer($footerData); } } }
php
public function customizerFooter() { if (get_field('footer_layout', 'options') !== 'customizer') { return; } $customizerFooter = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__footer_sections', 'options', 'id'); $classes = array(); $classes[] = 's-site-footer'; $classes[] = 'hidden-print'; $classes[] = (get_field('scroll_elevator_enabled', 'option')) ? 'scroll-elevator-toggle' : ''; $this->data['footerLayout']['template'] = 'customizer'; $this->data['footerLayout']['classes'] = implode(' ', $classes); if ($customizerFooter->hasItems) { foreach ($customizerFooter->repeater as $footerData) { $this->data['footerSections'][] = new \Municipio\Customizer\Footer($footerData); } } }
[ "public", "function", "customizerFooter", "(", ")", "{", "if", "(", "get_field", "(", "'footer_layout'", ",", "'options'", ")", "!==", "'customizer'", ")", "{", "return", ";", "}", "$", "customizerFooter", "=", "new", "\\", "Municipio", "\\", "Customizer", "...
Sends necessary data to the view for customizer footer @return void
[ "Sends", "necessary", "data", "to", "the", "view", "for", "customizer", "footer" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L200-L221
45,986
helsingborg-stad/Municipio
library/Oembed/YouTube.php
YouTube.getPlaylist
public function getPlaylist() : array { if (!defined('MUNICIPIO_GOOGLEAPIS_KEY') || !MUNICIPIO_GOOGLEAPIS_KEY || !isset($this->params['list'])) { return array(); } $theEnd = false; $nextPageToken = true; $items = array(); while ($nextPageToken) { $endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $this->params['list'] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY; if (is_string($nextPageToken) && !empty($nextPageToken)) { $endpointUrl .= '&pageToken=' . $nextPageToken; } $response = wp_remote_get($endpointUrl); // If response code is bad return if (wp_remote_retrieve_response_code($response) !== 200) { return array(); } $result = json_decode(wp_remote_retrieve_body($response)); $items = array_merge($items, $result->items); $nextPageToken = isset($result->nextPageToken) ? $result->nextPageToken : false; } return $items; }
php
public function getPlaylist() : array { if (!defined('MUNICIPIO_GOOGLEAPIS_KEY') || !MUNICIPIO_GOOGLEAPIS_KEY || !isset($this->params['list'])) { return array(); } $theEnd = false; $nextPageToken = true; $items = array(); while ($nextPageToken) { $endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $this->params['list'] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY; if (is_string($nextPageToken) && !empty($nextPageToken)) { $endpointUrl .= '&pageToken=' . $nextPageToken; } $response = wp_remote_get($endpointUrl); // If response code is bad return if (wp_remote_retrieve_response_code($response) !== 200) { return array(); } $result = json_decode(wp_remote_retrieve_body($response)); $items = array_merge($items, $result->items); $nextPageToken = isset($result->nextPageToken) ? $result->nextPageToken : false; } return $items; }
[ "public", "function", "getPlaylist", "(", ")", ":", "array", "{", "if", "(", "!", "defined", "(", "'MUNICIPIO_GOOGLEAPIS_KEY'", ")", "||", "!", "MUNICIPIO_GOOGLEAPIS_KEY", "||", "!", "isset", "(", "$", "this", "->", "params", "[", "'list'", "]", ")", ")", ...
Get playlist items @return array Playlist
[ "Get", "playlist", "items" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Oembed/YouTube.php#L131-L163
45,987
helsingborg-stad/Municipio
library/Comment/HoneyPot.php
HoneyPot.honeyPotValidateFieldContent
public function honeyPotValidateFieldContent($data) { if (isset($_POST[$this->field_name.'_fi']) && isset($_POST[$this->field_name.'_bl'])) { if (empty($_POST[$this->field_name.'_bl']) && $_POST[$this->field_name.'_fi'] == $this->field_content) { return $data; } wp_die(__("Could not verify that you are human (some hidden form fields are manipulated).", 'municipio')); } wp_die(__("Could not verify that you are human (some form fields are missing).", 'municipio')); }
php
public function honeyPotValidateFieldContent($data) { if (isset($_POST[$this->field_name.'_fi']) && isset($_POST[$this->field_name.'_bl'])) { if (empty($_POST[$this->field_name.'_bl']) && $_POST[$this->field_name.'_fi'] == $this->field_content) { return $data; } wp_die(__("Could not verify that you are human (some hidden form fields are manipulated).", 'municipio')); } wp_die(__("Could not verify that you are human (some form fields are missing).", 'municipio')); }
[ "public", "function", "honeyPotValidateFieldContent", "(", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "_POST", "[", "$", "this", "->", "field_name", ".", "'_fi'", "]", ")", "&&", "isset", "(", "$", "_POST", "[", "$", "this", "->", "field_name...
Validate honeypot fields before saving comment @param array $data The comment data @return array Comment data or die
[ "Validate", "honeypot", "fields", "before", "saving", "comment" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/HoneyPot.php#L64-L75
45,988
helsingborg-stad/Municipio
library/Helper/Query.php
Query.getPaginationData
public static function getPaginationData() { global $wp_query; $data = array(); $data['postType'] = $wp_query->query['post_type']; $data['postCount'] = $wp_query->post_count; $data['postTotal'] = $wp_query->found_posts; $data['pageIndex'] = ($wp_query->query['paged']) ? intval($wp_query->query['paged']) : 1; $data['pageTotal'] = $wp_query->max_num_pages; return $data; }
php
public static function getPaginationData() { global $wp_query; $data = array(); $data['postType'] = $wp_query->query['post_type']; $data['postCount'] = $wp_query->post_count; $data['postTotal'] = $wp_query->found_posts; $data['pageIndex'] = ($wp_query->query['paged']) ? intval($wp_query->query['paged']) : 1; $data['pageTotal'] = $wp_query->max_num_pages; return $data; }
[ "public", "static", "function", "getPaginationData", "(", ")", "{", "global", "$", "wp_query", ";", "$", "data", "=", "array", "(", ")", ";", "$", "data", "[", "'postType'", "]", "=", "$", "wp_query", "->", "query", "[", "'post_type'", "]", ";", "$", ...
Get pagination data from main query @return array Pagination data
[ "Get", "pagination", "data", "from", "main", "query" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Query.php#L11-L24
45,989
helsingborg-stad/Municipio
library/Helper/Controller.php
Controller.locateController
public static function locateController($controller) { preg_match_all('/^(single|archive)-/i', $controller, $matches); $controllers = array( str_replace('.blade.php', '', self::camelCase(basename($controller, '.php'))) ); if (isset($matches[1][0])) { $controllers[] = self::camelCase($matches[1][0]); } $searchPaths = array( get_stylesheet_directory() . '/library/Controller', get_template_directory() . '/library/Controller', ); /** * Apply filter to $searchPaths * @since 0.1.0 * @var array */ $searchPaths = apply_filters('Municipio/blade/controllers_search_paths', $searchPaths); foreach ($searchPaths as $path) { foreach ($controllers as $controller) { $file = $path . '/' . $controller . '.php'; if (!file_exists($file)) { continue; } return $file; } } return false; }
php
public static function locateController($controller) { preg_match_all('/^(single|archive)-/i', $controller, $matches); $controllers = array( str_replace('.blade.php', '', self::camelCase(basename($controller, '.php'))) ); if (isset($matches[1][0])) { $controllers[] = self::camelCase($matches[1][0]); } $searchPaths = array( get_stylesheet_directory() . '/library/Controller', get_template_directory() . '/library/Controller', ); /** * Apply filter to $searchPaths * @since 0.1.0 * @var array */ $searchPaths = apply_filters('Municipio/blade/controllers_search_paths', $searchPaths); foreach ($searchPaths as $path) { foreach ($controllers as $controller) { $file = $path . '/' . $controller . '.php'; if (!file_exists($file)) { continue; } return $file; } } return false; }
[ "public", "static", "function", "locateController", "(", "$", "controller", ")", "{", "preg_match_all", "(", "'/^(single|archive)-/i'", ",", "$", "controller", ",", "$", "matches", ")", ";", "$", "controllers", "=", "array", "(", "str_replace", "(", "'.blade.php...
Tries to locate a controller @param string $controller Controller name @return string Controller path
[ "Tries", "to", "locate", "a", "controller" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Controller.php#L12-L49
45,990
helsingborg-stad/Municipio
library/Helper/Controller.php
Controller.getNamespace
public static function getNamespace($classPath) { $src = file_get_contents($classPath); if (preg_match('/namespace\s+(.+?);/', $src, $m)) { return $m[1]; } return null; }
php
public static function getNamespace($classPath) { $src = file_get_contents($classPath); if (preg_match('/namespace\s+(.+?);/', $src, $m)) { return $m[1]; } return null; }
[ "public", "static", "function", "getNamespace", "(", "$", "classPath", ")", "{", "$", "src", "=", "file_get_contents", "(", "$", "classPath", ")", ";", "if", "(", "preg_match", "(", "'/namespace\\s+(.+?);/'", ",", "$", "src", ",", "$", "m", ")", ")", "{"...
Get a class's namespace @param string $classPath Path to the class php file @return string Namespace or null
[ "Get", "a", "class", "s", "namespace" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Controller.php#L80-L89
45,991
helsingborg-stad/Municipio
library/Widget/Source/HeaderWidget.php
HeaderWidget.implodeWrapperClass
protected function implodeWrapperClass() { if (is_array($this->data['widgetWrapperClass'])) { $this->data['widgetWrapperClass'] = implode(' ', $this->data['widgetWrapperClass']); } $re = '/class="(.*)"/'; $str = $this->data['args']['before_widget']; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); if (isset($matches[0][1])) { $widgetClass = 'c-navbar__widget widget widget_' . $this->config['id'] . ' ' . $this->data['widgetWrapperClass']; $oldClasses = $matches[0][1]; $this->data['args']['before_widget'] = str_replace($oldClasses, $widgetClass, $this->data['args']['before_widget']); } }
php
protected function implodeWrapperClass() { if (is_array($this->data['widgetWrapperClass'])) { $this->data['widgetWrapperClass'] = implode(' ', $this->data['widgetWrapperClass']); } $re = '/class="(.*)"/'; $str = $this->data['args']['before_widget']; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); if (isset($matches[0][1])) { $widgetClass = 'c-navbar__widget widget widget_' . $this->config['id'] . ' ' . $this->data['widgetWrapperClass']; $oldClasses = $matches[0][1]; $this->data['args']['before_widget'] = str_replace($oldClasses, $widgetClass, $this->data['args']['before_widget']); } }
[ "protected", "function", "implodeWrapperClass", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "data", "[", "'widgetWrapperClass'", "]", ")", ")", "{", "$", "this", "->", "data", "[", "'widgetWrapperClass'", "]", "=", "implode", "(", "' '", ...
Method to convert wrapper class array to string @return void
[ "Method", "to", "convert", "wrapper", "class", "array", "to", "string" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Widget/Source/HeaderWidget.php#L86-L102
45,992
helsingborg-stad/Municipio
library/Widget/Source/HeaderWidget.php
HeaderWidget.visibilityClasses
protected function visibilityClasses() { if (!$this->get_field('widget_header_visibility') || !is_array($this->get_field('widget_header_visibility')) || empty($this->get_field('widget_header_visibility'))) { return false; } $options = array( 'xs' => 'hidden-xs', 'sm' => 'hidden-sm', 'md' => 'hidden-md', 'lg' => 'hidden-lg' ); $options = apply_filters('Municipio/Widget/Source/NavigationWidget/visibilityClasses', $options); $classes = array(); foreach ($this->get_field('widget_header_visibility') as $device) { if (isset($options[$device])) { $classes[] = $options[$device]; } } if (!empty($classes)) { $this->data['widgetWrapperClass'] = array_merge($this->data['widgetWrapperClass'], $classes); return true; } return false; }
php
protected function visibilityClasses() { if (!$this->get_field('widget_header_visibility') || !is_array($this->get_field('widget_header_visibility')) || empty($this->get_field('widget_header_visibility'))) { return false; } $options = array( 'xs' => 'hidden-xs', 'sm' => 'hidden-sm', 'md' => 'hidden-md', 'lg' => 'hidden-lg' ); $options = apply_filters('Municipio/Widget/Source/NavigationWidget/visibilityClasses', $options); $classes = array(); foreach ($this->get_field('widget_header_visibility') as $device) { if (isset($options[$device])) { $classes[] = $options[$device]; } } if (!empty($classes)) { $this->data['widgetWrapperClass'] = array_merge($this->data['widgetWrapperClass'], $classes); return true; } return false; }
[ "protected", "function", "visibilityClasses", "(", ")", "{", "if", "(", "!", "$", "this", "->", "get_field", "(", "'widget_header_visibility'", ")", "||", "!", "is_array", "(", "$", "this", "->", "get_field", "(", "'widget_header_visibility'", ")", ")", "||", ...
Method to add visibility classes to widget wrapper based on ACF field @return void
[ "Method", "to", "add", "visibility", "classes", "to", "widget", "wrapper", "based", "on", "ACF", "field" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Widget/Source/HeaderWidget.php#L108-L138
45,993
helsingborg-stad/Municipio
library/Admin/General.php
General.removeUnwantedModuleMetaboxes
public function removeUnwantedModuleMetaboxes($postType) { $publicPostTypes = array_keys(\Municipio\Helper\PostType::getPublic()); $publicPostTypes[] = 'page'; if (!in_array($postType, $publicPostTypes)) { // Navigation settings remove_meta_box('acf-group_56d83cff12bb3', $postType, 'side'); // Display settings remove_meta_box('acf-group_56c33cf1470dc', $postType, 'side'); } }
php
public function removeUnwantedModuleMetaboxes($postType) { $publicPostTypes = array_keys(\Municipio\Helper\PostType::getPublic()); $publicPostTypes[] = 'page'; if (!in_array($postType, $publicPostTypes)) { // Navigation settings remove_meta_box('acf-group_56d83cff12bb3', $postType, 'side'); // Display settings remove_meta_box('acf-group_56c33cf1470dc', $postType, 'side'); } }
[ "public", "function", "removeUnwantedModuleMetaboxes", "(", "$", "postType", ")", "{", "$", "publicPostTypes", "=", "array_keys", "(", "\\", "Municipio", "\\", "Helper", "\\", "PostType", "::", "getPublic", "(", ")", ")", ";", "$", "publicPostTypes", "[", "]",...
Removes unwanted metaboxes from the module post types @param string $postType Post type @return void
[ "Removes", "unwanted", "metaboxes", "from", "the", "module", "post", "types" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/General.php#L73-L85
45,994
helsingborg-stad/Municipio
library/Admin/General.php
General.renamePrivate
public function renamePrivate() { if (!is_admin()) { return; } if (get_current_screen()->action !== '' && get_current_screen()->action !== 'add') { return; } add_filter('gettext', function ($translation, $text, $domain) { if ($text !== 'Private') { return $translation; } return __('Only for logged in users', 'municipio'); }, 10, 3); }
php
public function renamePrivate() { if (!is_admin()) { return; } if (get_current_screen()->action !== '' && get_current_screen()->action !== 'add') { return; } add_filter('gettext', function ($translation, $text, $domain) { if ($text !== 'Private') { return $translation; } return __('Only for logged in users', 'municipio'); }, 10, 3); }
[ "public", "function", "renamePrivate", "(", ")", "{", "if", "(", "!", "is_admin", "(", ")", ")", "{", "return", ";", "}", "if", "(", "get_current_screen", "(", ")", "->", "action", "!==", "''", "&&", "get_current_screen", "(", ")", "->", "action", "!==...
Renames the "private" post visibility to "only for logged in users" @return void
[ "Renames", "the", "private", "post", "visibility", "to", "only", "for", "logged", "in", "users" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/General.php#L91-L108
45,995
helsingborg-stad/Municipio
library/Admin/General.php
General.pageForPostsDropdown
public function pageForPostsDropdown($output, $r, $pages) { if ($r['name'] !== 'page_for_posts') { return $output; } $r['post_status'] = array('publish', 'private'); $pages = get_pages($r); $class = ''; if (! empty($r['class'])) { $class = " class='" . esc_attr($r['class']) . "'"; } $output = "<select name='" . esc_attr($r['name']) . "'" . $class . " id='" . esc_attr($r['id']) . "'>\n"; if ($r['show_option_no_change']) { $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n"; } if ($r['show_option_none']) { $output .= "\t<option value=\"" . esc_attr($r['option_none_value']) . '">' . $r['show_option_none'] . "</option>\n"; } add_filter('list_pages', array($this, 'listPagesTitle'), 100, 2); $output .= walk_page_dropdown_tree($pages, $r['depth'], $r); remove_filter('list_pages', array($this, 'listPagesTitle'), 100); $output .= "</select>\n"; return $output; }
php
public function pageForPostsDropdown($output, $r, $pages) { if ($r['name'] !== 'page_for_posts') { return $output; } $r['post_status'] = array('publish', 'private'); $pages = get_pages($r); $class = ''; if (! empty($r['class'])) { $class = " class='" . esc_attr($r['class']) . "'"; } $output = "<select name='" . esc_attr($r['name']) . "'" . $class . " id='" . esc_attr($r['id']) . "'>\n"; if ($r['show_option_no_change']) { $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n"; } if ($r['show_option_none']) { $output .= "\t<option value=\"" . esc_attr($r['option_none_value']) . '">' . $r['show_option_none'] . "</option>\n"; } add_filter('list_pages', array($this, 'listPagesTitle'), 100, 2); $output .= walk_page_dropdown_tree($pages, $r['depth'], $r); remove_filter('list_pages', array($this, 'listPagesTitle'), 100); $output .= "</select>\n"; return $output; }
[ "public", "function", "pageForPostsDropdown", "(", "$", "output", ",", "$", "r", ",", "$", "pages", ")", "{", "if", "(", "$", "r", "[", "'name'", "]", "!==", "'page_for_posts'", ")", "{", "return", "$", "output", ";", "}", "$", "r", "[", "'post_statu...
Show private pages in the "page for posts" dropdown @param string $output Dropdown markup @param array $r Arguments @param array $pages Default pages @return string New dropdown markup
[ "Show", "private", "pages", "in", "the", "page", "for", "posts", "dropdown" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/General.php#L117-L149
45,996
helsingborg-stad/Municipio
library/Walker/SidebarMenu.php
SidebarMenu.getChildOf
public function getChildOf($current_page, $elements) { $child_of = 0; if (is_a($current_page, '\WP_Post')) { $current_page = $current_page->ID; } foreach ($elements as $key => $element) { if (isset($element->ID) && isset($current_page) && $element->ID == $current_page) { $child_of = $element->ID; unset($elements[$key]); if (intval($element->menu_item_parent) > 0) { $child_of = $this->getChildOf(intval($element->menu_item_parent), $elements); } break; } } return $child_of; }
php
public function getChildOf($current_page, $elements) { $child_of = 0; if (is_a($current_page, '\WP_Post')) { $current_page = $current_page->ID; } foreach ($elements as $key => $element) { if (isset($element->ID) && isset($current_page) && $element->ID == $current_page) { $child_of = $element->ID; unset($elements[$key]); if (intval($element->menu_item_parent) > 0) { $child_of = $this->getChildOf(intval($element->menu_item_parent), $elements); } break; } } return $child_of; }
[ "public", "function", "getChildOf", "(", "$", "current_page", ",", "$", "elements", ")", "{", "$", "child_of", "=", "0", ";", "if", "(", "is_a", "(", "$", "current_page", ",", "'\\WP_Post'", ")", ")", "{", "$", "current_page", "=", "$", "current_page", ...
Find which the top parent for the current page @param integer $current_page Current page menu id @param array $elements Menu elements @return integer Menu parent id (child_of)
[ "Find", "which", "the", "top", "parent", "for", "the", "current", "page" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Walker/SidebarMenu.php#L79-L101
45,997
helsingborg-stad/Municipio
library/Helper/Acf.php
Acf.getFieldKey
public static function getFieldKey($fieldName, $fieldId) { if (isset(get_field_objects($fieldId)[$fieldName]['key'])) { return get_field_objects($fieldId)[$fieldName]['key']; } return false; }
php
public static function getFieldKey($fieldName, $fieldId) { if (isset(get_field_objects($fieldId)[$fieldName]['key'])) { return get_field_objects($fieldId)[$fieldName]['key']; } return false; }
[ "public", "static", "function", "getFieldKey", "(", "$", "fieldName", ",", "$", "fieldId", ")", "{", "if", "(", "isset", "(", "get_field_objects", "(", "$", "fieldId", ")", "[", "$", "fieldName", "]", "[", "'key'", "]", ")", ")", "{", "return", "get_fi...
Get ACF field key by fieldname, has to be run at action 'init' or later @param string $fieldName The field name @param string $fieldId Field ID can be post id, widget id, 'options' etc @return boolean/string
[ "Get", "ACF", "field", "key", "by", "fieldname", "has", "to", "be", "run", "at", "action", "init", "or", "later" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Acf.php#L13-L20
45,998
helsingborg-stad/Municipio
library/Helper/Image.php
Image.resize
public static function resize($originalImage, $width, $height, $crop = true) { $imagePath = false; // Image from attachment id if (is_numeric($originalImage)) { $imagePath = wp_get_attachment_url($originalImage); } elseif (in_array(substr($originalImage, 0, 7), array('https:/', 'http://'))) { $imagePath = self::urlToPath($originalImage); } if (!$imagePath) { return false; } $imagePath = self::removeImageSize($imagePath); if (!file_exists($imagePath)) { return false; } $imagePathInfo = pathinfo($imagePath); $ext = $imagePathInfo['extension']; $suffix = "{$width}x{$height}"; $destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}"; if (file_exists($destPath)) { return self::pathToUrl($destPath); } if (image_make_intermediate_size($imagePath, $width, $height, $crop)) { return self::pathToUrl($destPath); } return $originalImage; }
php
public static function resize($originalImage, $width, $height, $crop = true) { $imagePath = false; // Image from attachment id if (is_numeric($originalImage)) { $imagePath = wp_get_attachment_url($originalImage); } elseif (in_array(substr($originalImage, 0, 7), array('https:/', 'http://'))) { $imagePath = self::urlToPath($originalImage); } if (!$imagePath) { return false; } $imagePath = self::removeImageSize($imagePath); if (!file_exists($imagePath)) { return false; } $imagePathInfo = pathinfo($imagePath); $ext = $imagePathInfo['extension']; $suffix = "{$width}x{$height}"; $destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}"; if (file_exists($destPath)) { return self::pathToUrl($destPath); } if (image_make_intermediate_size($imagePath, $width, $height, $crop)) { return self::pathToUrl($destPath); } return $originalImage; }
[ "public", "static", "function", "resize", "(", "$", "originalImage", ",", "$", "width", ",", "$", "height", ",", "$", "crop", "=", "true", ")", "{", "$", "imagePath", "=", "false", ";", "// Image from attachment id", "if", "(", "is_numeric", "(", "$", "o...
Resizes an image to a specified size @param integer|string $originalImage Attachment id, path or url @param integer $width Target width @param integer $height Target height @param boolean $crop Crop or not? @return string Image url
[ "Resizes", "an", "image", "to", "a", "specified", "size" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Image.php#L15-L51
45,999
helsingborg-stad/Municipio
library/Helper/CacheBust.php
CacheBust.getRevManifest
public static function getRevManifest($childTheme = false) { $themePath = ($childTheme == true) ? get_stylesheet_directory() : get_template_directory(); $jsonPath = $themePath . apply_filters('Municipio/Helper/CacheBust/RevManifestPath', '/assets/dist/rev-manifest.json'); if (file_exists($jsonPath)) { return json_decode(file_get_contents($jsonPath), true); } elseif (WP_DEBUG) { echo '<div style="color:red">Error: Assets not built. Go to ' . $themePath . ' and run gulp. See '. $themePath . '/README.md for more info.</div>'; } }
php
public static function getRevManifest($childTheme = false) { $themePath = ($childTheme == true) ? get_stylesheet_directory() : get_template_directory(); $jsonPath = $themePath . apply_filters('Municipio/Helper/CacheBust/RevManifestPath', '/assets/dist/rev-manifest.json'); if (file_exists($jsonPath)) { return json_decode(file_get_contents($jsonPath), true); } elseif (WP_DEBUG) { echo '<div style="color:red">Error: Assets not built. Go to ' . $themePath . ' and run gulp. See '. $themePath . '/README.md for more info.</div>'; } }
[ "public", "static", "function", "getRevManifest", "(", "$", "childTheme", "=", "false", ")", "{", "$", "themePath", "=", "(", "$", "childTheme", "==", "true", ")", "?", "get_stylesheet_directory", "(", ")", ":", "get_template_directory", "(", ")", ";", "$", ...
Decode assets json to array @param boolean $childTheme Set child or parent theme path (defaults to parent) @return array containg assets filenames
[ "Decode", "assets", "json", "to", "array" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/CacheBust.php#L45-L55