_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q254900 | Protocol.checkLen | test | protected static function checkLen(string $type, string $bytes): void
{
$expectedLength = 0;
switch ($type) {
case self::BIT_B64:
$expectedLength = 8;
break;
case self::BIT_B32:
$expectedLength = 4;
break;
... | php | {
"resource": ""
} |
q254901 | Protocol.isSystemLittleEndian | test | public static function isSystemLittleEndian(): bool
{
// If we don't know if our system is big endian or not yet...
if (self::$isLittleEndianSystem === null) {
[$endianTest] = array_values(unpack('L1L', pack('V', 1)));
self::$isLittleEndianSystem = (int) $endianTest === 1;
... | php | {
"resource": ""
} |
q254902 | Protocol.getApiVersion | test | public function getApiVersion(int $apikey): int
{
switch ($apikey) {
case self::METADATA_REQUEST:
return self::API_VERSION0;
case self::PRODUCE_REQUEST:
if (version_compare($this->version, '0.10.0') >= 0) {
return self::API_VERSION2... | php | {
"resource": ""
} |
q254903 | Protocol.getApiText | test | public static function getApiText(int $apikey): string
{
$apis = [
self::PRODUCE_REQUEST => 'ProduceRequest',
self::FETCH_REQUEST => 'FetchRequest',
self::OFFSET_REQUEST => 'OffsetRequest',
self::METADATA_REQUEST => 'M... | php | {
"resource": ""
} |
q254904 | Router.before | test | public function before($methods, $pattern, $fn)
{
$pattern = $this->baseRoute . '/' . trim($pattern, '/');
$pattern = $this->baseRoute ? rtrim($pattern, '/') : $pattern;
foreach (explode('|', $methods) as $method) {
$this->beforeRoutes[$method][] = [
'pattern' =>... | php | {
"resource": ""
} |
q254905 | Router.match | test | public function match($methods, $pattern, $fn)
{
$pattern = $this->baseRoute . '/' . trim($pattern, '/');
$pattern = $this->baseRoute ? rtrim($pattern, '/') : $pattern;
foreach (explode('|', $methods) as $method) {
$this->afterRoutes[$method][] = [
'pattern' => $... | php | {
"resource": ""
} |
q254906 | Router.mount | test | public function mount($baseRoute, $fn)
{
// Track current base route
$curBaseRoute = $this->baseRoute;
// Build new base route string
$this->baseRoute .= $baseRoute;
// Call the callable
call_user_func($fn);
// Restore original base route
$this->bas... | php | {
"resource": ""
} |
q254907 | Router.getRequestMethod | test | public function getRequestMethod()
{
// Take the method as found in $_SERVER
$method = $_SERVER['REQUEST_METHOD'];
// If it's a HEAD request override it to being GET and prevent any output, as per HTTP Specification
// @url http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.... | php | {
"resource": ""
} |
q254908 | Router.getBasePath | test | public function getBasePath()
{
// Check if server base path is defined, if not define it.
if ($this->serverBasePath === null) {
$this->serverBasePath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
}
return $this->serverBasePath;
} | php | {
"resource": ""
} |
q254909 | Router.map | test | public function map($pattern, $callback, $pass_route = false) {
$url = $pattern;
$methods = array('*');
if (strpos($pattern, ' ') !== false) {
list($method, $url) = explode(' ', trim($pattern), 2);
$methods = explode('|', $method);
}
$this->routes[] = n... | php | {
"resource": ""
} |
q254910 | Router.route | test | public function route(Request $request) {
$url_decoded = urldecode( $request->url );
while ($route = $this->current()) {
if ($route !== false && $route->matchMethod($request->method) && $route->matchUrl($url_decoded, $this->case_sensitive)) {
return $route;
}
... | php | {
"resource": ""
} |
q254911 | Router.current | test | public function current() {
return isset($this->routes[$this->index]) ? $this->routes[$this->index] : false;
} | php | {
"resource": ""
} |
q254912 | Route.matchUrl | test | public function matchUrl($url, $case_sensitive = false) {
// Wildcard or exact match
if ($this->pattern === '*' || $this->pattern === $url) {
return true;
}
$ids = array();
$last_char = substr($this->pattern, -1);
// Get splat
if ($last_char === '*')... | php | {
"resource": ""
} |
q254913 | Dispatcher.run | test | public function run($name, array $params = array()) {
$output = '';
// Run pre-filters
if (!empty($this->filters[$name]['before'])) {
$this->filter($this->filters[$name]['before'], $params, $output);
}
// Run requested method
$output = $this->execute($this->... | php | {
"resource": ""
} |
q254914 | Dispatcher.get | test | public function get($name) {
return isset($this->events[$name]) ? $this->events[$name] : null;
} | php | {
"resource": ""
} |
q254915 | Dispatcher.clear | test | public function clear($name = null) {
if ($name !== null) {
unset($this->events[$name]);
unset($this->filters[$name]);
}
else {
$this->events = array();
$this->filters = array();
}
} | php | {
"resource": ""
} |
q254916 | Dispatcher.filter | test | public function filter($filters, &$params, &$output) {
$args = array(&$params, &$output);
foreach ($filters as $callback) {
$continue = $this->execute($callback, $args);
if ($continue === false) break;
}
} | php | {
"resource": ""
} |
q254917 | Dispatcher.execute | test | public static function execute($callback, array &$params = array()) {
if (is_callable($callback)) {
return is_array($callback) ?
self::invokeMethod($callback, $params) :
self::callFunction($callback, $params);
}
else {
throw new \Exception(... | php | {
"resource": ""
} |
q254918 | Dispatcher.callFunction | test | public static function callFunction($func, array &$params = array()) {
// Call static method
if (is_string($func) && strpos($func, '::') !== false) {
return call_user_func_array($func, $params);
}
switch (count($params)) {
case 0:
return $func();
... | php | {
"resource": ""
} |
q254919 | Dispatcher.invokeMethod | test | public static function invokeMethod($func, array &$params = array()) {
list($class, $method) = $func;
$instance = is_object($class);
switch (count($params)) {
case 0:
return ($instance) ?
$class->$method() :
$class::$method(... | php | {
"resource": ""
} |
q254920 | Request.init | test | public function init($properties = array()) {
// Set all the defined properties
foreach ($properties as $name => $value) {
$this->$name = $value;
}
// Get the requested URL without the base directory
if ($this->base != '/' && strlen($this->base) > 0 && strpos($this->... | php | {
"resource": ""
} |
q254921 | Request.getBody | test | public static function getBody() {
static $body;
if (!is_null($body)) {
return $body;
}
$method = self::getMethod();
if ($method == 'POST' || $method == 'PUT' || $method == 'PATCH') {
$body = file_get_contents('php://input');
}
return $... | php | {
"resource": ""
} |
q254922 | Request.getMethod | test | public static function getMethod() {
$method = self::getVar('REQUEST_METHOD', 'GET');
if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
$method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
elseif (isset($_REQUEST['_method'])) {
$method = $_REQUEST['_method'];... | php | {
"resource": ""
} |
q254923 | Request.getProxyIpAddress | test | public static function getProxyIpAddress() {
static $forwarded = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED'
);
$flags = \FILTER_FL... | php | {
"resource": ""
} |
q254924 | Request.parseQuery | test | public static function parseQuery($url) {
$params = array();
$args = parse_url($url);
if (isset($args['query'])) {
parse_str($args['query'], $params);
}
return $params;
} | php | {
"resource": ""
} |
q254925 | Response.status | test | public function status($code = null) {
if ($code === null) {
return $this->status;
}
if (array_key_exists($code, self::$codes)) {
$this->status = $code;
}
else {
throw new \Exception('Invalid status code.');
}
return $this;
... | php | {
"resource": ""
} |
q254926 | Response.header | test | public function header($name, $value = null) {
if (is_array($name)) {
foreach ($name as $k => $v) {
$this->headers[$k] = $v;
}
}
else {
$this->headers[$name] = $value;
}
return $this;
} | php | {
"resource": ""
} |
q254927 | Response.cache | test | public function cache($expires) {
if ($expires === false) {
$this->headers['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
$this->headers['Cache-Control'] = array(
'no-store, no-cache, must-revalidate',
'post-check=0, pre-check=0',
'max-age=0... | php | {
"resource": ""
} |
q254928 | Response.send | test | public function send() {
if (ob_get_length() > 0) {
ob_end_clean();
}
if (!headers_sent()) {
$this->sendHeaders();
}
echo $this->body;
$this->sent = true;
} | php | {
"resource": ""
} |
q254929 | Engine.init | test | public function init() {
static $initialized = false;
$self = $this;
if ($initialized) {
$this->vars = array();
$this->loader->reset();
$this->dispatcher->reset();
}
// Register default components
$this->loader->register('request', '\... | php | {
"resource": ""
} |
q254930 | Engine.handleError | test | public function handleError($errno, $errstr, $errfile, $errline) {
if ($errno & error_reporting()) {
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
}
} | php | {
"resource": ""
} |
q254931 | Engine.handleException | test | public function handleException($e) {
if ($this->get('flight.log_errors')) {
error_log($e->getMessage());
}
$this->error($e);
} | php | {
"resource": ""
} |
q254932 | Engine.map | test | public function map($name, $callback) {
if (method_exists($this, $name)) {
throw new \Exception('Cannot override an existing framework method.');
}
$this->dispatcher->set($name, $callback);
} | php | {
"resource": ""
} |
q254933 | Engine.register | test | public function register($name, $class, array $params = array(), $callback = null) {
if (method_exists($this, $name)) {
throw new \Exception('Cannot override an existing framework method.');
}
$this->loader->register($name, $class, $params, $callback);
} | php | {
"resource": ""
} |
q254934 | Engine.get | test | public function get($key = null) {
if ($key === null) return $this->vars;
return isset($this->vars[$key]) ? $this->vars[$key] : null;
} | php | {
"resource": ""
} |
q254935 | Engine.clear | test | public function clear($key = null) {
if (is_null($key)) {
$this->vars = array();
}
else {
unset($this->vars[$key]);
}
} | php | {
"resource": ""
} |
q254936 | Engine._start | test | public function _start() {
$dispatched = false;
$self = $this;
$request = $this->request();
$response = $this->response();
$router = $this->router();
// Allow filters to run
$this->after('start', function() use ($self) {
$self->stop();
});
... | php | {
"resource": ""
} |
q254937 | Engine._stop | test | public function _stop($code = null) {
$response = $this->response();
if (!$response->sent()) {
if ($code !== null) {
$response->status($code);
}
$response->write(ob_get_clean());
$response->send();
}
} | php | {
"resource": ""
} |
q254938 | Engine._route | test | public function _route($pattern, $callback, $pass_route = false) {
$this->router()->map($pattern, $callback, $pass_route);
} | php | {
"resource": ""
} |
q254939 | Engine._halt | test | public function _halt($code = 200, $message = '') {
$this->response()
->clear()
->status($code)
->write($message)
->send();
exit();
} | php | {
"resource": ""
} |
q254940 | Engine._error | test | public function _error($e) {
$msg = sprintf('<h1>500 Internal Server Error</h1>'.
'<h3>%s (%s)</h3>'.
'<pre>%s</pre>',
$e->getMessage(),
$e->getCode(),
$e->getTraceAsString()
);
try {
$this->response()
->cle... | php | {
"resource": ""
} |
q254941 | Engine._redirect | test | public function _redirect($url, $code = 303) {
$base = $this->get('flight.base_url');
if ($base === null) {
$base = $this->request()->base;
}
// Append base url to redirect url
if ($base != '/' && strpos($url, '://') === false) {
$url = $base . preg_repl... | php | {
"resource": ""
} |
q254942 | Engine._json | test | public function _json(
$data,
$code = 200,
$encode = true,
$charset = 'utf-8',
$option = 0
) {
$json = ($encode) ? json_encode($data, $option) : $data;
$this->response()
->status($code)
->header('Content-Type', 'application/json; chars... | php | {
"resource": ""
} |
q254943 | Engine._jsonp | test | public function _jsonp(
$data,
$param = 'jsonp',
$code = 200,
$encode = true,
$charset = 'utf-8',
$option = 0
) {
$json = ($encode) ? json_encode($data, $option) : $data;
$callback = $this->request()->query[$param];
$this->response()
... | php | {
"resource": ""
} |
q254944 | Engine._etag | test | public function _etag($id, $type = 'strong') {
$id = (($type === 'weak') ? 'W/' : '').$id;
$this->response()->header('ETag', $id);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
$_SERVER['HTTP_IF_NONE_MATCH'] === $id) {
$this->halt(304);
}
} | php | {
"resource": ""
} |
q254945 | Engine._lastModified | test | public function _lastModified($time) {
$this->response()->header('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $time));
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $time) {
$this->halt(304);
}
} | php | {
"resource": ""
} |
q254946 | Loader.register | test | public function register($name, $class, array $params = array(), $callback = null) {
unset($this->instances[$name]);
$this->classes[$name] = array($class, $params, $callback);
} | php | {
"resource": ""
} |
q254947 | Loader.load | test | public function load($name, $shared = true) {
$obj = null;
if (isset($this->classes[$name])) {
list($class, $params, $callback) = $this->classes[$name];
$exists = isset($this->instances[$name]);
if ($shared) {
$obj = ($exists) ?
... | php | {
"resource": ""
} |
q254948 | Loader.getInstance | test | public function getInstance($name) {
return isset($this->instances[$name]) ? $this->instances[$name] : null;
} | php | {
"resource": ""
} |
q254949 | Loader.newInstance | test | public function newInstance($class, array $params = array()) {
if (is_callable($class)) {
return call_user_func_array($class, $params);
}
switch (count($params)) {
case 0:
return new $class();
case 1:
return new $class($params[... | php | {
"resource": ""
} |
q254950 | Loader.loadClass | test | public static function loadClass($class) {
$class_file = str_replace(array('\\', '_'), '/', $class).'.php';
foreach (self::$dirs as $dir) {
$file = $dir.'/'.$class_file;
if (file_exists($file)) {
require $file;
return;
}
}
... | php | {
"resource": ""
} |
q254951 | Loader.addDirectory | test | public static function addDirectory($dir) {
if (is_array($dir) || is_object($dir)) {
foreach ($dir as $value) {
self::addDirectory($value);
}
}
else if (is_string($dir)) {
if (!in_array($dir, self::$dirs)) self::$dirs[] = $dir;
}
} | php | {
"resource": ""
} |
q254952 | View.fetch | test | public function fetch($file, $data = null) {
ob_start();
$this->render($file, $data);
$output = ob_get_clean();
return $output;
} | php | {
"resource": ""
} |
q254953 | View.getTemplate | test | public function getTemplate($file) {
$ext = $this->extension;
if (!empty($ext) && (substr($file, -1 * strlen($ext)) != $ext)) {
$file .= $ext;
}
if ((substr($file, 0, 1) == '/')) {
return $file;
}
return $this->path.'/'.$file;
} | php | {
"resource": ""
} |
q254954 | CycleDetector.isCyclic | test | public function isCyclic(Graph $graph)
{
// prepare stack
$recursionStack = [];
foreach ($graph->all() as $node) {
$recursionStack[$node->getKey()] = false;
}
// start analysis
$isCyclic = false;
foreach ($graph->getEdges() as $edge) {
... | php | {
"resource": ""
} |
q254955 | SizeOfTree.getAverageHeightOfGraph | test | public function getAverageHeightOfGraph()
{
$ns = [];
foreach ($this->graph->getRootNodes() as $node) {
array_push($ns, $this->getLongestBranch($node));
}
return round(array_sum($ns) / max(1, sizeof($ns)), 2);
} | php | {
"resource": ""
} |
q254956 | ConfigFileReaderJson.collapseArray | test | private function collapseArray(array $arr)
{
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr));
$result = [];
foreach ($iterator as $leafValue) {
$keys = [];
foreach (range(0, $iterator->getDepth()) as $depth) {
$keys[] = $ite... | php | {
"resource": ""
} |
q254957 | Finder.fetch | test | public function fetch(array $paths)
{
$files = array();
foreach ($paths as $path) {
if (is_dir($path)) {
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$directory = new RecursiveDirectoryIterator($path, $this->flags);
$ite... | php | {
"resource": ""
} |
q254958 | LcomVisitor.traverse | test | private function traverse(TreeNode $node)
{
if ($node->visited) {
return 0;
}
$node->visited = true;
foreach ($node->getAdjacents() as $adjacent) {
$this->traverse($adjacent);
}
return 1;
} | php | {
"resource": ""
} |
q254959 | Graph.getRootNodes | test | public function getRootNodes()
{
$roots = [];
foreach ($this->all() as $node) {
$isRoot = true;
foreach ($node->getEdges() as $edge) {
if ($edge->getTo() == $node) {
$isRoot = false;
}
}
if ($isRo... | php | {
"resource": ""
} |
q254960 | Composer.getComposerLockInstalled | test | protected function getComposerLockInstalled($rootPackageRequirements)
{
$rawInstalled = [[]];
// Find composer.lock file
$finder = new Finder(['lock'], $this->config->get('exclude'));
$files = $finder->fetch($this->config->get('files'));
// List all composer.lock found in t... | php | {
"resource": ""
} |
q254961 | ProgressBar.advance | test | public function advance()
{
$this->current++;
if ($this->hasAnsi()) {
$percent = round($this->current / $this->max * 100);
$this->output->write("\x0D");
$this->output->write("\x1B[2K");
$this->output->write(sprintf('... %s%% ...', $percent));
... | php | {
"resource": ""
} |
q254962 | ProgressBar.hasAnsi | test | protected function hasAnsi()
{
if (DIRECTORY_SEPARATOR === '\\') {
return
0 >= version_compare('10.0.10586',
PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD)
|| false !== getenv('ANSICON')
... | php | {
"resource": ""
} |
q254963 | I18nTextDomainFixerSniff.process_no_parameters | test | public function process_no_parameters( $stackPtr, $group_name, $matched_content ) {
$target_param = $this->target_functions[ $matched_content ];
if ( 1 !== $target_param ) {
// Only process the no param case as fixable if the text domain is expected to be the first parameter.
$this->phpcsFile->addWarning( '... | php | {
"resource": ""
} |
q254964 | Sniff.process | test | public function process( File $phpcsFile, $stackPtr ) {
$this->init( $phpcsFile );
return $this->process_token( $stackPtr );
} | php | {
"resource": ""
} |
q254965 | Sniff.init | test | protected function init( File $phpcsFile ) {
$this->phpcsFile = $phpcsFile;
$this->tokens = $phpcsFile->getTokens();
} | php | {
"resource": ""
} |
q254966 | Sniff.addFixableMessage | test | protected function addFixableMessage( $message, $stackPtr, $is_error = true, $code = 'Found', $data = array(), $severity = 0 ) {
return $this->throwMessage( $message, $stackPtr, $is_error, $code, $data, $severity, true );
} | php | {
"resource": ""
} |
q254967 | Sniff.merge_custom_array | test | public static function merge_custom_array( $custom, $base = array(), $flip = true ) {
if ( true === $flip ) {
$base = array_filter( $base );
}
if ( empty( $custom ) || ! \is_array( $custom ) ) {
return $base;
}
if ( true === $flip ) {
$custom = array_fill_keys( $custom, false );
}
if ( empty( ... | php | {
"resource": ""
} |
q254968 | Sniff.get_last_ptr_on_line | test | protected function get_last_ptr_on_line( $stackPtr ) {
$tokens = $this->tokens;
$currentLine = $tokens[ $stackPtr ]['line'];
$nextPtr = ( $stackPtr + 1 );
while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ]['line'] === $currentLine ) {
$nextPtr++;
// Do nothing, we just want the last to... | php | {
"resource": ""
} |
q254969 | Sniff.is_assignment | test | protected function is_assignment( $stackPtr ) {
static $valid = array(
\T_VARIABLE => true,
\T_CLOSE_SQUARE_BRACKET => true,
);
// Must be a variable, constant or closing square bracket (see below).
if ( ! isset( $valid[ $this->tokens[ $stackPtr ]['code'] ] ) ) {
return false;
}
$nex... | php | {
"resource": ""
} |
q254970 | Sniff.is_token_namespaced | test | protected function is_token_namespaced( $stackPtr ) {
$prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true );
if ( false === $prev ) {
return false;
}
if ( \T_NS_SEPARATOR !== $this->tokens[ $prev ]['code'] ) {
return false;
}
$before_prev = $this-... | php | {
"resource": ""
} |
q254971 | Sniff.is_only_sanitized | test | protected function is_only_sanitized( $stackPtr ) {
// If it isn't being sanitized at all.
if ( ! $this->is_sanitized( $stackPtr ) ) {
return false;
}
// If this isn't set, we know the value must have only been casted, because
// is_sanitized() would have returned false otherwise.
if ( ! isset( $this->... | php | {
"resource": ""
} |
q254972 | Sniff.is_safe_casted | test | protected function is_safe_casted( $stackPtr ) {
// Get the last non-empty token.
$prev = $this->phpcsFile->findPrevious(
Tokens::$emptyTokens,
( $stackPtr - 1 ),
null,
true
);
if ( false === $prev ) {
return false;
}
// Check if it is a safe cast.
return isset( $this->safe_casts[ $this-... | php | {
"resource": ""
} |
q254973 | Sniff.get_array_access_keys | test | protected function get_array_access_keys( $stackPtr, $all = true ) {
$keys = array();
if ( \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) {
return $keys;
}
$current = $stackPtr;
do {
// Find the next non-empty token.
$open_bracket = $this->phpcsFile->findNext(
Tokens::$emptyTokens,
... | php | {
"resource": ""
} |
q254974 | Sniff.get_array_access_key | test | protected function get_array_access_key( $stackPtr ) {
$keys = $this->get_array_access_keys( $stackPtr, false );
if ( isset( $keys[0] ) ) {
return $keys[0];
}
return false;
} | php | {
"resource": ""
} |
q254975 | Sniff.is_comparison | test | protected function is_comparison( $stackPtr, $include_coalesce = true ) {
$comparisonTokens = Tokens::$comparisonTokens;
if ( false === $include_coalesce ) {
unset( $comparisonTokens[ \T_COALESCE ] );
}
// We first check if this is a switch statement (switch ( $var )).
if ( isset( $this->tokens[ $stackPt... | php | {
"resource": ""
} |
q254976 | Sniff.is_in_array_comparison | test | protected function is_in_array_comparison( $stackPtr ) {
$function_ptr = $this->is_in_function_call( $stackPtr, $this->arrayCompareFunctions, true, true );
if ( false === $function_ptr ) {
return false;
}
$function_name = $this->tokens[ $function_ptr ]['content'];
if ( true === $this->arrayCompareFunction... | php | {
"resource": ""
} |
q254977 | Sniff.get_use_type | test | protected function get_use_type( $stackPtr ) {
// USE keywords inside closures.
$next = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true );
if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code'] ) {
return 'closure';
}
// USE keywords for traits.
$valid_scopes = array(
... | php | {
"resource": ""
} |
q254978 | Sniff.get_interpolated_variables | test | protected function get_interpolated_variables( $string ) {
$variables = array();
if ( preg_match_all( '/(?P<backslashes>\\\\*)\$(?P<symbol>\w+)/', $string, $match_sets, \PREG_SET_ORDER ) ) {
foreach ( $match_sets as $matches ) {
if ( ! isset( $matches['backslashes'] ) || ( \strlen( $matches['backslashes'] ) ... | php | {
"resource": ""
} |
q254979 | Sniff.does_function_call_have_parameters | test | public function does_function_call_have_parameters( $stackPtr ) {
// Check for the existence of the token.
if ( false === isset( $this->tokens[ $stackPtr ] ) ) {
return false;
}
// Is this one of the tokens this function handles ?
if ( false === \in_array( $this->tokens[ $stackPtr ]['code'], array( \T_ST... | php | {
"resource": ""
} |
q254980 | Sniff.get_function_call_parameter_count | test | public function get_function_call_parameter_count( $stackPtr ) {
if ( false === $this->does_function_call_have_parameters( $stackPtr ) ) {
return 0;
}
return \count( $this->get_function_call_parameters( $stackPtr ) );
} | php | {
"resource": ""
} |
q254981 | Sniff.get_function_call_parameter | test | public function get_function_call_parameter( $stackPtr, $param_offset ) {
$parameters = $this->get_function_call_parameters( $stackPtr );
if ( false === isset( $parameters[ $param_offset ] ) ) {
return false;
}
return $parameters[ $param_offset ];
} | php | {
"resource": ""
} |
q254982 | Sniff.find_array_open_close | test | protected function find_array_open_close( $stackPtr ) {
/*
* Determine the array opener & closer.
*/
if ( \T_ARRAY === $this->tokens[ $stackPtr ]['code'] ) {
if ( isset( $this->tokens[ $stackPtr ]['parenthesis_opener'] ) ) {
$opener = $this->tokens[ $stackPtr ]['parenthesis_opener'];
if ( isset( $... | php | {
"resource": ""
} |
q254983 | Sniff.determine_namespace | test | public function determine_namespace( $stackPtr ) {
// Check for the existence of the token.
if ( ! isset( $this->tokens[ $stackPtr ] ) ) {
return '';
}
// Check for scoped namespace {}.
if ( ! empty( $this->tokens[ $stackPtr ]['conditions'] ) ) {
$namespacePtr = $this->phpcsFile->getCondition( $stackP... | php | {
"resource": ""
} |
q254984 | Sniff.get_declared_namespace_name | test | public function get_declared_namespace_name( $stackPtr ) {
// Check for the existence of the token.
if ( false === $stackPtr || ! isset( $this->tokens[ $stackPtr ] ) ) {
return false;
}
if ( \T_NAMESPACE !== $this->tokens[ $stackPtr ]['code'] ) {
return false;
}
$nextToken = $this->phpcsFile->findN... | php | {
"resource": ""
} |
q254985 | Sniff.is_class_constant | test | public function is_class_constant( $stackPtr ) {
if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_CONST !== $this->tokens[ $stackPtr ]['code'] ) {
return false;
}
// Note: traits can not declare constants.
$valid_scopes = array(
'T_CLASS' => true,
'T_ANON_CLASS' => true,
'T_INTERFACE' => true... | php | {
"resource": ""
} |
q254986 | Sniff.is_class_property | test | public function is_class_property( $stackPtr ) {
if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) {
return false;
}
// Note: interfaces can not declare properties.
$valid_scopes = array(
'T_CLASS' => true,
'T_ANON_CLASS' => true,
'T_TRAIT' ... | php | {
"resource": ""
} |
q254987 | Sniff.valid_direct_scope | test | protected function valid_direct_scope( $stackPtr, array $valid_scopes ) {
if ( empty( $this->tokens[ $stackPtr ]['conditions'] ) ) {
return false;
}
/*
* Check only the direct wrapping scope of the token.
*/
$conditions = array_keys( $this->tokens[ $stackPtr ]['conditions'] );
$ptr = array_po... | php | {
"resource": ""
} |
q254988 | ValidHookNameSniff.prepare_regex | test | protected function prepare_regex() {
$extra = '';
if ( '' !== $this->additionalWordDelimiters && \is_string( $this->additionalWordDelimiters ) ) {
$extra = preg_quote( $this->additionalWordDelimiters, '`' );
}
return sprintf( $this->punctuation_regex, $extra );
} | php | {
"resource": ""
} |
q254989 | ValidHookNameSniff.transform | test | protected function transform( $string, $regex, $transform_type = 'full' ) {
switch ( $transform_type ) {
case 'case':
return strtolower( $string );
case 'punctuation':
return preg_replace( $regex, '_', $string );
case 'full':
default:
return preg_replace( $regex, '_', strtolower( $string ) ... | php | {
"resource": ""
} |
q254990 | ValidHookNameSniff.transform_complex_string | test | protected function transform_complex_string( $string, $regex, $transform_type = 'full' ) {
$output = preg_split( '`([\{\}\$\[\] ])`', $string, -1, \PREG_SPLIT_DELIM_CAPTURE );
$is_variable = false;
$has_braces = false;
$braces = 0;
foreach ( $output as $i => $part ) {
if ( \in_array( $part, array( ... | php | {
"resource": ""
} |
q254991 | DeprecatedClassesSniff.getGroups | test | public function getGroups() {
// Make sure all array keys are lowercase.
$this->deprecated_classes = array_change_key_case( $this->deprecated_classes, CASE_LOWER );
return array(
'deprecated_classes' => array(
'classes' => array_keys( $this->deprecated_classes ),
),
);
} | php | {
"resource": ""
} |
q254992 | DiscouragedConstantsSniff.process_arbitrary_tstring | test | public function process_arbitrary_tstring( $stackPtr ) {
$content = $this->tokens[ $stackPtr ]['content'];
if ( ! isset( $this->discouraged_constants[ $content ] ) ) {
return;
}
$next = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
if ( false !== $next && \T_OPEN_PARE... | php | {
"resource": ""
} |
q254993 | DiscouragedConstantsSniff.process_parameters | test | public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) {
$function_name = strtolower( $matched_content );
$target_param = $this->target_functions[ $function_name ];
// Was the target parameter passed ?
if ( ! isset( $parameters[ $target_param ] ) ) {
return;
}
$raw... | php | {
"resource": ""
} |
q254994 | CapitalPDangitSniff.retrieve_misspellings | test | protected function retrieve_misspellings( $match_stack ) {
$mispelled = array();
foreach ( $match_stack as $match ) {
// Deal with multi-dimensional arrays when capturing offset.
if ( \is_array( $match ) ) {
$match = $match[0];
}
if ( 'WordPress' !== $match ) {
$mispelled[] = $match;
}
}
... | php | {
"resource": ""
} |
q254995 | PostsPerPageSniff.callback | test | public function callback( $key, $val, $line, $group ) {
$this->posts_per_page = (int) $this->posts_per_page;
if ( $val > $this->posts_per_page ) {
return 'Detected high pagination limit, `%s` is set to `%s`';
}
return false;
} | php | {
"resource": ""
} |
q254996 | PHPCSHelper.set_config_data | test | public static function set_config_data( $key, $value, $temp = false ) {
Config::setConfigData( $key, $value, $temp );
} | php | {
"resource": ""
} |
q254997 | PHPCSHelper.get_tab_width | test | public static function get_tab_width( File $phpcsFile ) {
$tab_width = 4;
if ( isset( $phpcsFile->config->tabWidth ) && $phpcsFile->config->tabWidth > 0 ) {
$tab_width = $phpcsFile->config->tabWidth;
}
return $tab_width;
} | php | {
"resource": ""
} |
q254998 | GlobalVariablesOverrideSniff.process_global_statement | test | protected function process_global_statement( $stackPtr, $in_function_scope ) {
/*
* Collect the variables to watch for.
*/
$search = array();
$ptr = ( $stackPtr + 1 );
while ( isset( $this->tokens[ $ptr ] ) ) {
$var = $this->tokens[ $ptr ];
// Halt the loop at end of statement.
if ( \T_SEMICO... | php | {
"resource": ""
} |
q254999 | GlobalVariablesOverrideSniff.add_error | test | protected function add_error( $stackPtr, $data = array() ) {
if ( empty( $data ) ) {
$data[] = $this->tokens[ $stackPtr ]['content'];
}
$this->phpcsFile->addError(
'Overriding WordPress globals is prohibited. Found assignment to %s',
$stackPtr,
'Prohibited',
$data
);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.