code
stringlengths
17
296k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public function __construct(int $id) { $this->id = $id; }
UsernameByIdRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/User/UsernameByIdRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/User/UsernameByIdRequest.php
MIT
public function __construct(string $username) { $this->username = $username; }
UserProfileRequest constructor. @param string $username
__construct
php
jikan-me/jikan
src/Request/User/UserProfileRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/User/UserProfileRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
PersonPicturesRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Person/PersonPicturesRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Person/PersonPicturesRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
MangaStatsRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Manga/MangaStatsRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaStatsRequest.php
MIT
public function __construct(int $id, ?string $topic = null) { $this->id = $id; $this->topic = $topic; }
MangaForumRequest constructor. @param int $id @param string|null $topic
__construct
php
jikan-me/jikan
src/Request/Manga/MangaForumRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaForumRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
MangaCharactersRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Manga/MangaCharactersRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaCharactersRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
MangaPicturesRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Manga/MangaPicturesRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaPicturesRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
MangaRecommendationsRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Manga/MangaRecommendationsRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaRecommendationsRequest.php
MIT
public function __construct(int $id, int $page = 1, string $sort = Constants::REVIEWS_SORT_MOST_VOTED, bool $spoilers = true, bool $preliminary = true) { $this->id = $id; $this->page = $page; $this->sort = $sort; $this->spoilers = $spoilers; $this->preliminary = $preliminary; }
MangaReviewsRequest constructor. @param int $id @param int $page
__construct
php
jikan-me/jikan
src/Request/Manga/MangaReviewsRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaReviewsRequest.php
MIT
public function __construct(int $id, int $page = 1) { $this->id = $id; $this->page = ($page - 1) * 75; }
MangaRecentlyUpdatedByUsersRequest constructor. @param int $id @param int $page
__construct
php
jikan-me/jikan
src/Request/Manga/MangaRecentlyUpdatedByUsersRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaRecentlyUpdatedByUsersRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
MangaMoreInfoRequest constructor @param int $id
__construct
php
jikan-me/jikan
src/Request/Manga/MangaMoreInfoRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Manga/MangaMoreInfoRequest.php
MIT
public function __construct(int $id, int $page = 1, string $sort = Constants::REVIEWS_SORT_MOST_VOTED, bool $spoilers = true, bool $preliminary = true) { $this->id = $id; $this->page = $page; $this->sort = $sort; $this->spoilers = $spoilers; $this->preliminary = $preliminary; }
AnimeReviewsRequest constructor. @param int $id @param int $page
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeReviewsRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeReviewsRequest.php
MIT
public function __construct(int $id, int $episodeId) { $this->id = $id; $this->episodeId = $episodeId; }
AnimeEpisodeRequest constructor. @param int $id @param int $page
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeEpisodeRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeEpisodeRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
AnimeRecommendationsRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeRecommendationsRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeRecommendationsRequest.php
MIT
public function __construct(int $id, ?string $topic = null) { $this->id = $id; $this->topic = $topic; }
AnimeForumRequest constructor. @param int $id @param string|null $topic
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeForumRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeForumRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
AnimeStatsRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeStatsRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeStatsRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
AnimeCharactersAndStaffRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeCharactersAndStaffRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeCharactersAndStaffRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
AnimeVideosRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeVideosRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeVideosRequest.php
MIT
public function __construct(int $id, int $page = 1) { $this->id = $id; $this->page = ($page - 1) * 75; }
AnimeRecentlyUpdatedByUsersRequest constructor. @param int $id @param int $page
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeRecentlyUpdatedByUsersRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeRecentlyUpdatedByUsersRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
AnimeMoreInfoRequest constructor @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeMoreInfoRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeMoreInfoRequest.php
MIT
public function __construct(int $id) { $this->id = $id; }
AnimePicturesRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimePicturesRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimePicturesRequest.php
MIT
public function __construct(int $id, int $page) { $this->id = $id; $this->page = $page; }
AnimeVideosEpisodesRequest constructor. @param int $id
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeVideosEpisodesRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeVideosEpisodesRequest.php
MIT
public function __construct(int $id, int $page = 1) { $this->id = $id; $this->page = ($page - 1) * 100; }
AnimeEpisodesRequest constructor. @param int $id @param int $page
__construct
php
jikan-me/jikan
src/Request/Anime/AnimeEpisodesRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Anime/AnimeEpisodesRequest.php
MIT
public function __construct(?string $query = null, int $page = 1) { $this->query = $query; $this->page = $page; $this->query = $this->query ?? ''; $querySize = strlen($this->query); if ($querySize > 0 && $querySize < 3) { throw new BadResponseException('Search with queries require at least 3 characters'); } }
CharacterSearchRequest constructor. @param string|null $query @param int $page
__construct
php
jikan-me/jikan
src/Request/Search/CharacterSearchRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Search/CharacterSearchRequest.php
MIT
public function __construct(?string $query = null, int $page = 1) { $this->query = $query; $this->page = $page; $this->query = $this->query ?? ''; $querySize = strlen($this->query); if ($querySize > 0 && $querySize < 3) { throw new BadResponseException('Search with queries require at least 3 characters'); } }
MangaSearchRequest constructor. @param string|null $query @param int $page
__construct
php
jikan-me/jikan
src/Request/Search/MangaSearchRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Search/MangaSearchRequest.php
MIT
public function __construct(?string $query = null, int $page = 1) { $this->query = $query; $this->page = $page; $this->query = $this->query ?? ''; $querySize = strlen($this->query); if ($querySize > 0 && $querySize < 3) { throw new BadResponseException('Search with queries require at least 3 characters'); } }
PersonSearchRequest constructor. @param string|null $query @param int $page
__construct
php
jikan-me/jikan
src/Request/Search/PersonSearchRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Search/PersonSearchRequest.php
MIT
public function __construct(?string $query = null, int $page = 1) { $this->query = $query; $this->page = $page; $this->query = $this->query ?? ''; $querySize = strlen($this->query); if ($querySize > 0 && $querySize < 3) { throw new BadResponseException('Search with queries require at least 3 characters'); } }
AnimeSearchRequest constructor. @param string|null $query @param int $page
__construct
php
jikan-me/jikan
src/Request/Search/AnimeSearchRequest.php
https://github.com/jikan-me/jikan/blob/master/src/Request/Search/AnimeSearchRequest.php
MIT
public function __construct(?string $fullId = null) { if ($fullId === null) { $this->regenerate(); } else { $this->fullId = $fullId; $this->decode(); } }
Id constructor. If id is known, pass it here, if you want to generate a new id, pass nothing @param string|null $fullId
__construct
php
aternosorg/mclogs
core/src/Id.php
https://github.com/aternosorg/mclogs/blob/master/core/src/Id.php
MIT
protected function deobfuscateContent() { /** * @var ?Information $version */ $version = $this->analysis->getFilteredInsights(VanillaVersionInformation::class)[0] ?? null; if (!$version) { return; } $version = $version->getValue(); try { $map = $this->getObfuscationMap($version); } catch (\Exception) { $map = null; } if ($map === null) { return; } $this->obfuscatedContent = new ObfuscatedString($this->data, $map); if ($content = $this->obfuscatedContent->getMappedContent()) { $this->data = $content; $this->log = (new Detective())->setLogFile(new StringLogFile($this->data))->detect(); $this->log->parse(); } }
deobfuscate the content of this log @return void
deobfuscateContent
php
aternosorg/mclogs
core/src/Log.php
https://github.com/aternosorg/mclogs/blob/master/core/src/Log.php
MIT
public function renew() { $config = Config::Get('storage'); /** * @var StorageInterface $storage */ $storage = $config['storages'][$this->id->getStorage()]['class']; $storage::Renew($this->id); }
Renew the expiry timestamp to expand the ttl
renew
php
aternosorg/mclogs
core/src/Log.php
https://github.com/aternosorg/mclogs/blob/master/core/src/Log.php
MIT
protected function curlPost($encoded_data) { if ($this->use_ssl) { $uri = 'https://'.$this->getPaypalHost().'/cgi-bin/webscr'; $this->post_uri = $uri; } else { $uri = 'http://'.$this->getPaypalHost().'/cgi-bin/webscr'; $this->post_uri = $uri; } $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cert/api_cert_chain.crt"); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location); curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); if ($this->force_ssl_v3) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); } $this->response = curl_exec($ch); $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE)); if ($this->response === false || $this->response_status == '0') { $errno = curl_errno($ch); $errstr = curl_error($ch); throw new Exception("cURL error: [$errno] $errstr"); } }
Post Back Using cURL Sends the post back to PayPal using the cURL library. Called by the processIpn() method if the use_curl property is true. Throws an exception if the post fails. Populates the response, response_status, and post_uri properties on success. @param string The post data as a URL encoded string
curlPost
php
MicahCarrick/PHP-PayPal-IPN
ipnlistener.php
https://github.com/MicahCarrick/PHP-PayPal-IPN/blob/master/ipnlistener.php
BSD-3-Clause
protected function fsockPost($encoded_data) { if ($this->use_ssl) { $uri = 'ssl://'.$this->getPaypalHost(); $port = '443'; $this->post_uri = $uri.'/cgi-bin/webscr'; } else { $uri = $this->getPaypalHost(); // no "http://" in call to fsockopen() $port = '80'; $this->post_uri = 'http://'.$uri.'/cgi-bin/webscr'; } $fp = fsockopen($uri, $port, $errno, $errstr, $this->timeout); if (!$fp) { // fsockopen error throw new Exception("fsockopen error: [$errno] $errstr"); } $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: ".$this->getPaypalHost()."\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: ".strlen($encoded_data)."\r\n"; $header .= "Connection: Close\r\n\r\n"; fputs($fp, $header.$encoded_data."\r\n\r\n"); while(!feof($fp)) { if (empty($this->response)) { // extract HTTP status from first line $this->response .= $status = fgets($fp, 1024); $this->response_status = trim(substr($status, 9, 4)); } else { $this->response .= fgets($fp, 1024); } } fclose($fp); }
Post Back Using fsockopen() Sends the post back to PayPal using the fsockopen() function. Called by the processIpn() method if the use_curl property is false. Throws an exception if the post fails. Populates the response, response_status, and post_uri properties on success. @param string The post data as a URL encoded string
fsockPost
php
MicahCarrick/PHP-PayPal-IPN
ipnlistener.php
https://github.com/MicahCarrick/PHP-PayPal-IPN/blob/master/ipnlistener.php
BSD-3-Clause
public function getPostUri() { return $this->post_uri; }
Get POST URI Returns the URI that was used to send the post back to PayPal. This can be useful for troubleshooting connection problems. The default URI would be "ssl://www.sandbox.paypal.com:443/cgi-bin/webscr" @return string
getPostUri
php
MicahCarrick/PHP-PayPal-IPN
ipnlistener.php
https://github.com/MicahCarrick/PHP-PayPal-IPN/blob/master/ipnlistener.php
BSD-3-Clause
public function getResponse() { return $this->response; }
Get Response Returns the entire response from PayPal as a string including all the HTTP headers. @return string
getResponse
php
MicahCarrick/PHP-PayPal-IPN
ipnlistener.php
https://github.com/MicahCarrick/PHP-PayPal-IPN/blob/master/ipnlistener.php
BSD-3-Clause
public function getResponseStatus() { return $this->response_status; }
Get Response Status Returns the HTTP response status code from PayPal. This should be "200" if the post back was successful. @return string
getResponseStatus
php
MicahCarrick/PHP-PayPal-IPN
ipnlistener.php
https://github.com/MicahCarrick/PHP-PayPal-IPN/blob/master/ipnlistener.php
BSD-3-Clause
public function requirePostMethod() { // require POST requests if ($_SERVER['REQUEST_METHOD'] && $_SERVER['REQUEST_METHOD'] != 'POST') { header('Allow: POST', true, 405); throw new Exception("Invalid HTTP request method."); } }
Require Post Method Throws an exception and sets a HTTP 405 response header if the request method was not POST.
requirePostMethod
php
MicahCarrick/PHP-PayPal-IPN
ipnlistener.php
https://github.com/MicahCarrick/PHP-PayPal-IPN/blob/master/ipnlistener.php
BSD-3-Clause
public function register() { return array( T_CLASS, T_INTERFACE, T_ANON_CLASS, ); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Functions/ScopeOrderSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Functions/ScopeOrderSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $function = $stackPtr; $scopes = array( 0 => T_PUBLIC, 1 => T_PROTECTED, 2 => T_PRIVATE, ); $whitelisted = array( '__construct', 'setUp', 'tearDown', ); while ($function) { $end = null; if (isset($tokens[$stackPtr]['scope_closer'])) { $end = $tokens[$stackPtr]['scope_closer']; } $function = $phpcsFile->findNext( array( T_ANON_CLASS, T_FUNCTION, ), $function + 1, $end ); if (T_ANON_CLASS === $tokens[$function]['code']) { $function = $tokens[$function]['scope_closer']; continue; } if (isset($tokens[$function]['parenthesis_opener'])) { $scope = $phpcsFile->findPrevious($scopes, $function -1, $stackPtr); $name = $phpcsFile->findNext( T_STRING, $function + 1, $tokens[$function]['parenthesis_opener'] ); if ($scope && $name && !in_array( $tokens[$name]['content'], $whitelisted, true ) ) { $current = array_keys($scopes, $tokens[$scope]['code'], true); $current = $current[0]; $error = 'Declare public methods first,' .'then protected ones and finally private ones'; if (isset($previous) && $current < $previous) { $phpcsFile->addError( $error, $scope, 'Invalid' ); } $previous = $current; } } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Functions/ScopeOrderSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Functions/ScopeOrderSniff.php
MIT
public function register() { return [ T_FUNCTION, ]; }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Functions/ReturnTypeSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Functions/ReturnTypeSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $methodProperties = $phpcsFile->getMethodProperties($stackPtr); $type = $methodProperties['return_type_token']; if (false === $type || 'void' !== strtolower($tokens[$type]['content'])) { return; } $next = $stackPtr; do { if (!isset($tokens[$stackPtr]['scope_closer'])) { break; } $next = $phpcsFile->findNext( T_RETURN, $next + 1, $tokens[$stackPtr]['scope_closer'] ); if (false === $next) { break; } $conditions = $tokens[$next]['conditions']; $lastScope = key(array_slice($conditions, -1, null, true)); if ($stackPtr !== $lastScope) { continue; } if (T_SEMICOLON !== $tokens[$next + 1]['code']) { $error = 'Use return null; when a function explicitly '; $error .= 'returns null values and use return; '; $error .= 'when the function returns void values'; $phpcsFile->addError( $error, $next, 'Invalid' ); } } while (true); }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Functions/ReturnTypeSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Functions/ReturnTypeSniff.php
MIT
public function register() { return array( T_FUNCTION, ); }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Functions/ArgumentsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Functions/ArgumentsSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $function = $tokens[$stackPtr]; $openerLine = $tokens[$function['parenthesis_opener']]['line']; $closerLine = $tokens[$function['parenthesis_closer']]['line']; if ($openerLine !== $closerLine) { $error = 'Declare all the arguments on the same line '; $error .= 'as the method/function name, '; $error .= 'no matter how many arguments there are.'; $phpcsFile->addError( $error, $stackPtr, 'Invalid' ); } }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Functions/ArgumentsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Functions/ArgumentsSniff.php
MIT
public function register() { return [ T_THROW, T_RETURN, ]; }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $elem = $tokens[$stackPtr]; // find the function/closure we're currently in and an if or case statement $function = $phpcsFile->findPrevious([T_FUNCTION, T_CLOSURE], $stackPtr); if (false === $function) { return; } $opener = $phpcsFile->findPrevious( $this->_openers, $stackPtr, $tokens[$function]['scope_opener'] ); $scopeCloserLine = -1; if (false === isset($tokens[$opener]['scope_closer'])) { return; } if ($opener) { $scopeCloserLine = $tokens[$tokens[$opener]['scope_closer']]['line']; } // check whether the return / throw is within a if or case statement if ($opener && $elem['line'] <= $scopeCloserLine) { // check whether there's an elseif, else or break // following the if or case statement $condition = $phpcsFile->findNext( $this->_conditions, $stackPtr + 1, $tokens[$function]['scope_closer'] ); if (false !== $condition) { if (T_CASE === $tokens[$opener]['code']) { $next = $phpcsFile->findNext( [T_CASE, T_DEFAULT], $stackPtr + 1, $tokens[$function]['scope_closer'] ); $err = true; if (false !== $next) { $err = $tokens[$condition]['line'] < $tokens[$next]['line']; } } else { $err = $tokens[$condition]['line'] === $scopeCloserLine; } if ($err) { $error = 'Do not use else, elseif, break after if and '; $error .= 'case conditions which return or throw something'; $phpcsFile->addError( $error, $stackPtr, 'Invalid' ); } } } }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php
MIT
public function register() { return array(T_RETURN); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $current = $stackPtr; $previousLine = $tokens[$stackPtr]['line'] - 1; $prevLineTokens = array(); $spaceTokens = [ 'T_WHITESPACE', 'T_COMMENT', 'T_DOC_COMMENT_CLOSE_TAG', 'T_DOC_COMMENT_WHITESPACE', ]; while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) { if ($tokens[$current]['line'] === $previousLine && !in_array($tokens[$current]['type'], $spaceTokens, true) ) { $prevLineTokens[] = $tokens[$current]['type']; } $current--; } if (isset($prevLineTokens[0]) && ($prevLineTokens[0] === 'T_OPEN_CURLY_BRACKET' || $prevLineTokens[0] === 'T_COLON') ) { return; } if (count($prevLineTokens) > 0) { $fix = $phpcsFile->addFixableError( 'Missing blank line before return statement', $stackPtr, 'MissedBlankLineBeforeReturn' ); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); $i = 1; while ($tokens[$stackPtr-$i]['type'] === 'T_WHITESPACE') { $i++; } $phpcsFile->fixer->addNewline($stackPtr-$i); $phpcsFile->fixer->endChangeset(); } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile All the tokens found in the document. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
MIT
public function register() { return array(T_OPEN_TAG); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Files/AlphanumericFilenameSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Files/AlphanumericFilenameSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $filename = $phpcsFile->getFilename(); if ($filename === 'STDIN') { return; } $filename = str_replace('_', '', basename($filename, '.php')); if (false === ctype_alnum($filename)) { $error = sprintf( 'Filename "%s" contains non alphanumeric characters', $filename ); $phpcsFile->addError($error, $stackPtr, 'Invalid'); $phpcsFile->recordMetric($stackPtr, 'Alphanumeric filename', 'no'); } else { $phpcsFile->recordMetric($stackPtr, 'Alphanumeric filename', 'yes'); } // Ignore the rest of the file. return ($phpcsFile->numTokens + 1); }
Process. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Files/AlphanumericFilenameSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Files/AlphanumericFilenameSniff.php
MIT
public function register() { return array( T_INC, T_DEC, ); }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/ControlStructure/UnaryOperatorsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/ControlStructure/UnaryOperatorsSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (T_CLASS === $tokens[$stackPtr + 1]['code'] || T_SELF === $tokens[$stackPtr + 1]['code'] ) { return; } if ((T_VARIABLE !== $tokens[$stackPtr - 1]['code'] && T_VARIABLE !== $tokens[$stackPtr + 1]['code']) && (T_OBJECT_OPERATOR !== $tokens[$stackPtr - 2]['code']) && (']' !== $tokens[$stackPtr - 1]['content']) ) { $error = 'Place unary operators adjacent to the affected variable'; $phpcsFile->addError($error, $stackPtr, 'Invalid'); } }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/ControlStructure/UnaryOperatorsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/ControlStructure/UnaryOperatorsSniff.php
MIT
public function register() { return array( T_IS_EQUAL, T_IS_NOT_EQUAL, ); }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $phpcsFile->addWarning( 'Always use identical comparison unless you need type juggling', $stackPtr, 'Warning' ); }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php
MIT
public function register() { return array( T_IF, T_ELSEIF, ); }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $opener = $tokens[$stackPtr]['parenthesis_opener']; $closer = $tokens[$stackPtr]['parenthesis_closer']; do { $comparison = $phpcsFile->findNext($this->_yodas, $opener + 1, $closer); if (false === $comparison) { break; } if (T_VARIABLE === $tokens[$comparison - 2]['code'] && T_VARIABLE !== $tokens[$comparison + 2]['code'] ) { $error = 'Use Yoda conditions when checking a variable against '; $error .= 'an expression to avoid an accidental assignment '; $error .= 'inside the condition statement.'; $phpcsFile->addError($error, $stackPtr, 'Invalid'); } $opener = $comparison + 1; } while ($opener < $closer); }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php
MIT
public function register() { return array(T_CLASS); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Classes/MultipleClassesOneFileSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Classes/MultipleClassesOneFileSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { if ($this->currentFile !== $phpcsFile->getFilename()) { $this->classCount = 0; $this->currentFile = $phpcsFile->getFilename(); } $this->classCount++; if ($this->classCount > 1) { $phpcsFile->addError( 'Multiple classes defined in a single file', $stackPtr, 'Invalid' ); } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile All the tokens found in the document. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Classes/MultipleClassesOneFileSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Classes/MultipleClassesOneFileSniff.php
MIT
public function register() { return array( T_CLASS, T_ANON_CLASS ); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Classes/PropertyDeclarationSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Classes/PropertyDeclarationSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $end = null; if (isset($tokens[$stackPtr]['scope_closer'])) { $end = $tokens[$stackPtr]['scope_closer']; } $scope = $phpcsFile->findNext( T_FUNCTION, $stackPtr, $end ); $wantedTokens = array( T_PUBLIC, T_PROTECTED, T_PRIVATE, T_ANON_CLASS ); while ($scope) { if (T_ANON_CLASS === $tokens[$scope]['code']) { $scope = $tokens[$scope]['scope_closer']; continue; } $scope = $phpcsFile->findNext( $wantedTokens, $scope + 1, $end ); if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE && $tokens[$scope]['code'] !== T_ANON_CLASS ) { $phpcsFile->addError( 'Declare class properties before methods', $scope, 'Invalid' ); } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Classes/PropertyDeclarationSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Classes/PropertyDeclarationSniff.php
MIT
public function register() { return Tokens::$comparisonTokens; }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/BinaryOperatorSpacingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/BinaryOperatorSpacingSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr -1]['code'] !== T_WHITESPACE || $tokens[$stackPtr +1]['code'] !== T_WHITESPACE ) { $fix = $phpcsFile->addFixableError( 'Add a single space around binary operators', $stackPtr, 'Invalid' ); if ($fix === true) { if ($tokens[$stackPtr -1]['code'] !== T_WHITESPACE) { $phpcsFile->fixer->addContentBefore($stackPtr, ' '); } if ($tokens[$stackPtr +1]['code'] !== T_WHITESPACE) { $phpcsFile->fixer->addContent($stackPtr, ' '); } } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/BinaryOperatorSpacingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/BinaryOperatorSpacingSniff.php
MIT
public function register() { return array(T_WHITESPACE); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/DiscourageFitzinatorSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/DiscourageFitzinatorSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); // Make sure this is trailing whitespace. $line = $tokens[$stackPtr]['line']; if (($stackPtr < count($tokens) - 1) && $tokens[$stackPtr + 1]['line'] === $line ) { return; } if (strpos($tokens[$stackPtr]['content'], "\n") > 0 || strpos($tokens[$stackPtr]['content'], "\r") > 0 ) { $warning = 'Please trim any trailing whitespace'; $fix = $phpcsFile->addFixableWarning($warning, $stackPtr, 'Invalid'); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->replaceToken($stackPtr, ''); $phpcsFile->fixer->addNewlineBefore($stackPtr); $phpcsFile->fixer->endChangeset(); } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile All the tokens found in the document. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/DiscourageFitzinatorSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/DiscourageFitzinatorSniff.php
MIT
public function register() { return array( T_COMMA, ); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/CommaSpacingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/CommaSpacingSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $line = $tokens[$stackPtr]['line']; if ($tokens[$stackPtr + 1]['line'] === $line && $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE ) { $fix = $phpcsFile->addFixableError( 'Add a single space after each comma delimiter', $stackPtr, 'Invalid' ); if ($fix === true) { $phpcsFile->fixer->addContent($stackPtr, ' '); } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/CommaSpacingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/CommaSpacingSniff.php
MIT
public function register() { return Tokens::$assignmentTokens; }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/AssignmentSpacingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/AssignmentSpacingSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE || $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) && $tokens[$stackPtr - 1]['content'] !== 'strict_types' ) { $fix = $phpcsFile->addFixableError( 'Add a single space around assignment operators', $stackPtr, 'Invalid' ); if ($fix === true) { $replacement = $tokens[$stackPtr]['content']; if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) { $replacement = ' '.$replacement; } if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) { $replacement .= ' '; } $phpcsFile->fixer->replaceToken($stackPtr, $replacement); } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Whitespace/AssignmentSpacingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Whitespace/AssignmentSpacingSniff.php
MIT
public function register() { return [ T_NAMESPACE ]; }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/LicenseSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/LicenseSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { if (false === $phpcsFile->findPrevious( [T_COMMENT, T_DOC_COMMENT_OPEN_TAG], $stackPtr ) ) { $phpcsFile->addWarning( 'The license block has to be present at the top of every PHP file, before the namespace', $stackPtr, 'Warning' ); } }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/LicenseSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/LicenseSniff.php
MIT
protected function processTags($phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); foreach ($tokens[$commentStart]['comment_tags'] as $tag) { $name = $tokens[$tag]['content']; if (in_array($name, $this->blacklist, true)) { $error = sprintf('The %s tag is not allowed.', $name); $phpcsFile->addError($error, $tag, 'Blacklisted'); } } parent::processTags($phpcsFile, $stackPtr, $commentStart); }
Processes each tag and raise an error if there are blacklisted tags. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @param int $commentStart Position in the stack where the comment started. @return void
processTags
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/ClassCommentSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/ClassCommentSniff.php
MIT
protected function processReturn( File $phpcsFile, $stackPtr, $commentStart ) { if ($this->isInheritDoc($phpcsFile, $stackPtr)) { return; } $tokens = $phpcsFile->getTokens(); // Only check for a return comment if a non-void return statement exists if (isset($tokens[$stackPtr]['scope_opener'])) { // Start inside the function $start = $phpcsFile->findNext( T_OPEN_CURLY_BRACKET, $stackPtr, $tokens[$stackPtr]['scope_closer'] ); for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) { // Skip closures if ($tokens[$i]['code'] === T_CLOSURE) { $i = $tokens[$i]['scope_closer']; continue; } // Found a return not in a closure statement // Run the check on the first which is not only 'return;' if ($tokens[$i]['code'] === T_RETURN && $this->isMatchingReturn($tokens, $i) ) { parent::processReturn($phpcsFile, $stackPtr, $commentStart); break; } } } }
Process the return comment of this function comment. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @param int $commentStart The position in the stack where the comment started. @return void
processReturn
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/FunctionCommentSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/FunctionCommentSniff.php
MIT
protected function isInheritDoc(File $phpcsFile, $stackPtr) { $start = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1); $end = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, $start); $content = $phpcsFile->getTokensAsString($start, $end - $start); return preg_match('#({@inheritdoc}|(?<!{)@inheritdoc(?!}))#i', $content) === 1; }
Is the comment an inheritdoc? @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return boolean True if the comment is an inheritdoc
isInheritDoc
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/FunctionCommentSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/FunctionCommentSniff.php
MIT
protected function processParams( File $phpcsFile, $stackPtr, $commentStart ) { if ($this->isInheritDoc($phpcsFile, $stackPtr)) { return; } parent::processParams($phpcsFile, $stackPtr, $commentStart); }
Process the function parameter comments. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @param int $commentStart The position in the stack where the comment started. @return void
processParams
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/FunctionCommentSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/FunctionCommentSniff.php
MIT
protected function isMatchingReturn($tokens, $returnPos) { do { $returnPos++; } while ($tokens[$returnPos]['code'] === T_WHITESPACE); return $tokens[$returnPos]['code'] !== T_SEMICOLON; }
Is the return statement matching? @param array $tokens Array of tokens @param int $returnPos Stack position of the T_RETURN token to process @return boolean True if the return does not return anything
isMatchingReturn
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/FunctionCommentSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/FunctionCommentSniff.php
MIT
public function register() { return [ T_DOC_COMMENT_TAG, T_BOOL_CAST, T_INT_CAST, T_DOUBLE_CAST, ]; }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/TypeHintingSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/TypeHintingSniff.php
MIT
public function register() { return [ T_DOC_COMMENT_TAG, ]; }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/AnnotationsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/AnnotationsSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $closer = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, $stackPtr); if (false !== $next = $phpcsFile->findNext( $this->register(), $stackPtr + 1, $closer ) ) { $first = preg_replace( self::PATTERN, '$1', $tokens[$stackPtr]['content'] ); $second = preg_replace( self::PATTERN, '$1', $tokens[$next]['content'] ); $stackPtrLine = $tokens[$stackPtr]['line']; $nextLine = $tokens[$next]['line']; if ($first !== $second && $stackPtrLine + 2 > $nextLine) { $error = 'Group annotations together '; $error .= 'so that annotations of the same type '; $error .= 'immediately follow each other, and annotations '; $error .= 'of a different type are separated '; $error .= 'by a single blank line'; $fixable = $phpcsFile->addFixableError( $error, $stackPtr, 'Invalid' ); if (true === $fixable) { $indentPtr = $phpcsFile->findFirstOnLine( T_DOC_COMMENT_WHITESPACE, $next ); $indentStr = $phpcsFile->getTokensAsString($indentPtr, 1); $content = "\n{$indentStr}*"; $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->addContentBefore($next - 1, $content); $phpcsFile->fixer->endChangeset(); } } } }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Commenting/AnnotationsSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Commenting/AnnotationsSniff.php
MIT
public function register() { return array( T_NEW, ); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Objects/ObjectInstantiationSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Objects/ObjectInstantiationSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $allowed = array( T_STRING, T_NS_SEPARATOR, T_VARIABLE, T_STATIC, T_SELF, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_OPEN_SQUARE_BRACKET, T_CLOSE_SQUARE_BRACKET, ); $object = $stackPtr; $line = $tokens[$object]['line']; if (T_ANON_CLASS === $tokens[$object + 2]['code']) { if ($tokens[$object + 3]['code'] !== T_OPEN_PARENTHESIS) { $phpcsFile->addError( 'Use parentheses when instantiating classes', $stackPtr, 'Invalid' ); } return; } while ($object && $tokens[$object]['line'] === $line) { $object = $phpcsFile->findNext($allowed, $object + 1); if ($tokens[$object]['line'] === $line && !in_array($tokens[$object + 1]['code'], $allowed, true) ) { if ($tokens[$object + 1]['code'] !== T_OPEN_PARENTHESIS) { $phpcsFile->addError( 'Use parentheses when instantiating classes', $stackPtr, 'Invalid' ); } break; } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Objects/ObjectInstantiationSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Objects/ObjectInstantiationSniff.php
MIT
public function register() { return array( T_INTERFACE, T_TRAIT, T_EXTENDS, T_ABSTRACT ); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $line = $tokens[$stackPtr]['line']; while ($tokens[$stackPtr]['line'] === $line) { /* * Suffix interfaces with Interface; */ if ('T_INTERFACE' === $tokens[$stackPtr]['type']) { $name = $phpcsFile->findNext(T_STRING, $stackPtr); if ($name && substr($tokens[$name]['content'], -9) !== 'Interface') { $phpcsFile->addError( 'Interface name is not suffixed with "Interface"', $stackPtr, 'InvalidInterfaceName' ); } break; } /* * Suffix traits with Trait; */ if ('T_TRAIT' === $tokens[$stackPtr]['type']) { $name = $phpcsFile->findNext(T_STRING, $stackPtr); if ($name && substr($tokens[$name]['content'], -5) !== 'Trait') { $phpcsFile->addError( 'Trait name is not suffixed with "Trait"', $stackPtr, 'InvalidTraitName' ); } break; } /* * Suffix exceptions with Exception; */ if ('T_EXTENDS' === $tokens[$stackPtr]['type']) { $extend = $phpcsFile->findNext(T_STRING, $stackPtr); $class = $phpcsFile->findPrevious(T_CLASS, $stackPtr); if ($extend && false !== $class && substr($tokens[$extend]['content'], -9) === 'Exception' ) { $name = $phpcsFile->findNext(T_STRING, $class); if ($name && substr($tokens[$name]['content'], -9) !== 'Exception' ) { $phpcsFile->addError( 'Exception name is not suffixed with "Exception"', $stackPtr, 'InvalidExceptionName' ); } } break; } /* * Prefix abstract classes with Abstract. */ if ('T_ABSTRACT' === $tokens[$stackPtr]['type']) { $name = $phpcsFile->findNext(T_STRING, $stackPtr); $function = $phpcsFile->findNext(T_FUNCTION, $stackPtr); // making sure we're not dealing with an abstract function if ((null === $function|| $name < $function) && strpos($tokens[$name]['content'], 'Abstract') !== 0 ) { $phpcsFile->addError( 'Abstract class name is not prefixed with "Abstract"', $stackPtr, 'InvalidAbstractName' ); } break; } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile All the tokens found in the document. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php
MIT
public function register() { return array( T_ARRAY, T_OPEN_SHORT_ARRAY, ); }
Returns an array of tokens this test wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $open = $tokens[$stackPtr]; if ($open['code'] === T_ARRAY) { $closePtr = $open['parenthesis_closer']; } else { $closePtr = $open['bracket_closer']; } if ($open['line'] !== $tokens[$closePtr]['line']) { $arrayIsNotEmpty = $phpcsFile->findPrevious( array( T_WHITESPACE, T_COMMENT, T_ARRAY, T_OPEN_PARENTHESIS, T_OPEN_SHORT_ARRAY, ), $closePtr - 1, $stackPtr, true ); if ($arrayIsNotEmpty !== false) { $lastCommaPtr = $phpcsFile->findPrevious( T_COMMA, $closePtr, $stackPtr ); if ($lastCommaPtr === false) { $lastCommaPtr = 0; } while ($lastCommaPtr < $closePtr -1) { $lastCommaPtr++; if ($tokens[$lastCommaPtr]['code'] !== T_WHITESPACE && $tokens[$lastCommaPtr]['code'] !== T_PHPCS_IGNORE && $tokens[$lastCommaPtr]['code'] !== T_COMMENT ) { $fix = $phpcsFile->addFixableError( 'Add a comma after each item in a multi-line array', $stackPtr, 'Invalid' ); if ($fix === true) { $ptr = $phpcsFile->findPrevious( array(T_WHITESPACE, T_COMMENT, T_PHPCS_IGNORE), $closePtr-1, $stackPtr, true ); $phpcsFile->fixer->addContent($ptr, ','); $phpcsFile->fixer->endChangeset(); } break; } } } } }
Processes this test, when one of its tokens is encountered. @param File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php
MIT
public function register() { return array( T_THROW, ); }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Errors/ExceptionMessageSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Errors/ExceptionMessageSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); // No parenthesis found after the throw, no additional check required if ($opener === false) { return; } // check the content of the found parenthesis, // only if it is in the same statement as the throw $endOfStatement = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); if (($endOfStatement > $opener) && $phpcsFile->findNext( T_STRING_CONCAT, $tokens[$opener]['parenthesis_opener'], $tokens[$opener]['parenthesis_closer'] ) ) { $error = 'Exception and error message strings must be '; $error .= 'concatenated using sprintf'; $phpcsFile->addError($error, $stackPtr, 'Invalid'); } }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Errors/ExceptionMessageSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Errors/ExceptionMessageSniff.php
MIT
public function register() { return array( T_STRING, ); }
Registers the tokens that this sniff wants to listen for. @return array
register
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Errors/UserDeprecatedSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Errors/UserDeprecatedSniff.php
MIT
public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['content'] !== 'trigger_error') { return; } $pos = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); $opener = $tokens[$pos]['parenthesis_opener']; $closer = $tokens[$pos]['parenthesis_closer']; do { $string = $phpcsFile->findNext(T_STRING, $opener, $closer); if (false === $string) { break; } $opener = $string + 1; if ($tokens[$string]['content'] !== 'E_USER_DEPRECATED') { continue; } if ('@' === $tokens[$stackPtr -1]['content']) { continue; } if ('@' === $tokens[$stackPtr - 2]['content'] && 'T_NS_SEPARATOR' === $tokens[$stackPtr - 1]['type'] ) { continue; } $error = 'Calls to trigger_error with type E_USER_DEPRECATED '; $error .= 'must be switched to opt-in via @ operator'; $phpcsFile->addError($error, $stackPtr, 'Invalid'); break; } while ($opener < $closer); }
Called when one of the token types that this sniff is listening for is found. @param File $phpcsFile The file where the token was found. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return (count($tokens) + 1) to skip the rest of the file.
process
php
djoos/Symfony-coding-standard
Symfony/Sniffs/Errors/UserDeprecatedSniff.php
https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Errors/UserDeprecatedSniff.php
MIT
public function __construct(array $properties = []) { foreach ($properties as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } }
VideoGrant class constructor. @param array $properties A list of properties with values to assign upon initializing the class.
__construct
php
agence104/livekit-server-sdk-php
src/VideoGrant.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/VideoGrant.php
Apache-2.0
public function __construct(array $properties = []) { foreach ($properties as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } }
RoomCreateOptions class constructor. @param array $properties A list of properties with values to assign upon initializing the class.
__construct
php
agence104/livekit-server-sdk-php
src/RoomCreateOptions.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/RoomCreateOptions.php
Apache-2.0
public function __construct(?string $apiKey = NULL, ?string $apiSecret = NULL) { $apiKey = $apiKey ?? getenv('LIVEKIT_API_KEY'); $apiSecret = $apiSecret ?? getenv('LIVEKIT_API_SECRET'); if (!$apiKey || !$apiSecret) { throw new \Exception('ApiKey and apiSecret are required.'); } $this->apiKey = $apiKey; $this->apiSecret = $apiSecret; }
AccessToken Constructor. @param string|null $apiKey The LiveKit API Key, can be set in env LIVEKIT_API_KEY. @param string|null $apiSecret The LiveKit API Secret Key, can be set in env LIVEKIT_API_SECRET. @throws \Exception
__construct
php
agence104/livekit-server-sdk-php
src/AccessToken.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/AccessToken.php
Apache-2.0
public function __construct(array $properties = []) { foreach ($properties as $property => $value) { if (property_exists($this, $property)) { if ($property == 'videoGrant') { $this->{$property} = new VideoGrant($value); } else { $this->{$property} = $value; } } } }
ClaimGrants class constructor. @param array $properties A list of properties with values to assign upon initializing the class.
__construct
php
agence104/livekit-server-sdk-php
src/ClaimGrants.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/ClaimGrants.php
Apache-2.0
public function __construct(?string $apiKey = NULL, ?string $apiSecret = NULL) { $apiKey = $apiKey ?? getenv('LIVEKIT_API_KEY'); $apiSecret = $apiSecret ?? getenv('LIVEKIT_API_SECRET'); if (!$apiKey || !$apiSecret) { throw new \Exception('ApiKey and apiSecret are required.'); } $this->accessToken = new AccessToken($apiKey, $apiSecret); }
WebhookReceiver Constructor. @param string|null $apiKey The LiveKit API Key, can be set in env LIVEKIT_API_KEY. @param string|null $apiSecret The LiveKit API Secret Key, can be set in env LIVEKIT_API_SECRET. @throws \Exception
__construct
php
agence104/livekit-server-sdk-php
src/WebhookReceiver.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/WebhookReceiver.php
Apache-2.0
public function __construct(array $properties = []) { foreach ($properties as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } }
AccessTokenOptions class constructor. @param array $properties A list of properties with values to assign upon initializing the class.
__construct
php
agence104/livekit-server-sdk-php
src/AccessTokenOptions.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/AccessTokenOptions.php
Apache-2.0
public function __construct(array $properties = []) { foreach ($properties as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } }
EncodedOutputs class constructor. @param array $properties A list of properties with values to assign upon initializing the class.
__construct
php
agence104/livekit-server-sdk-php
src/EncodedOutputs.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/EncodedOutputs.php
Apache-2.0
public function __construct(?string $host = NULL, ?string $apiKey = NULL, ?string $apiSecret = NULL) { // Using LIVEKIT_HOST is deprecated and support will be removed in the next // version. Use LIVEKIT_URL instead. $host = $host ?? getenv('LIVEKIT_URL') ?? getenv('LIVEKIT_HOST'); $apiKey = $apiKey ?? getenv('LIVEKIT_API_KEY'); $apiSecret = $apiSecret ?? getenv('LIVEKIT_API_SECRET'); if (!$apiKey || !$apiSecret) { throw new \Exception('ApiKey and apiSecret are required.'); } $this->host = $host; $this->apiKey = $apiKey; $this->apiSecret = $apiSecret; }
BaseServiceClient Class Constructor. @param string|null $host The hostname including protocol. i.e. 'https://cluster.livekit.io'. @param string|null $apiKey The API Key, can be set in env var LIVEKIT_API_KEY. @param string|null $apiSecret The API Secret, can be set in env var LIVEKIT_API_SECRET. @throws \Exception
__construct
php
agence104/livekit-server-sdk-php
src/BaseServiceClient.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/BaseServiceClient.php
Apache-2.0
public function getItems() { return $this->items; }
Generated from protobuf field <code>repeated .livekit.SIPOutboundTrunkInfo items = 1;</code> @return \Google\Protobuf\Internal\RepeatedField
getItems
php
agence104/livekit-server-sdk-php
src/proto/Livekit/ListSIPOutboundTrunkResponse.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/proto/Livekit/ListSIPOutboundTrunkResponse.php
Apache-2.0
public function setItems($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Livekit\SIPOutboundTrunkInfo::class); $this->items = $arr; return $this; }
Generated from protobuf field <code>repeated .livekit.SIPOutboundTrunkInfo items = 1;</code> @param \Livekit\SIPOutboundTrunkInfo[]|\Google\Protobuf\Internal\RepeatedField $var @return $this
setItems
php
agence104/livekit-server-sdk-php
src/proto/Livekit/ListSIPOutboundTrunkResponse.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/proto/Livekit/ListSIPOutboundTrunkResponse.php
Apache-2.0
public function getInfo() { return $this->info; }
Generated from protobuf field <code>repeated .livekit.StreamInfo info = 1;</code> @return \Google\Protobuf\Internal\RepeatedField
getInfo
php
agence104/livekit-server-sdk-php
src/proto/Livekit/StreamInfoList.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/proto/Livekit/StreamInfoList.php
Apache-2.0
public function setInfo($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Livekit\StreamInfo::class); $this->info = $arr; return $this; }
Generated from protobuf field <code>repeated .livekit.StreamInfo info = 1;</code> @param \Livekit\StreamInfo[]|\Google\Protobuf\Internal\RepeatedField $var @return $this
setInfo
php
agence104/livekit-server-sdk-php
src/proto/Livekit/StreamInfoList.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/proto/Livekit/StreamInfoList.php
Apache-2.0
public function getRule() { return $this->rule; }
Generated from protobuf field <code>.livekit.SIPDispatchRule rule = 1;</code> @return \Livekit\SIPDispatchRule|null
getRule
php
agence104/livekit-server-sdk-php
src/proto/Livekit/CreateSIPDispatchRuleRequest.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/proto/Livekit/CreateSIPDispatchRuleRequest.php
Apache-2.0
public function setRule($var) { GPBUtil::checkMessage($var, \Livekit\SIPDispatchRule::class); $this->rule = $var; return $this; }
Generated from protobuf field <code>.livekit.SIPDispatchRule rule = 1;</code> @param \Livekit\SIPDispatchRule $var @return $this
setRule
php
agence104/livekit-server-sdk-php
src/proto/Livekit/CreateSIPDispatchRuleRequest.php
https://github.com/agence104/livekit-server-sdk-php/blob/master/src/proto/Livekit/CreateSIPDispatchRuleRequest.php
Apache-2.0