_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q250600
FinalCallback.finalize
validation
protected function finalize($function) { $response = $this->container->get(self::RESPONSE); if (is_string($function) === true) { $stream = $response->getBody(); $stream->write((string) $function); } $instanceof = $function instanceof ResponseInterface; return $instanceof ? $function : $response; }
php
{ "resource": "" }
q250601
CallbackHandler.middleware
validation
protected function middleware(FinalCallback $callback, ServerRequestInterface $request) { $response = $this->container->get(self::RESPONSE); if (interface_exists(Application::MIDDLEWARE) === true) { $middleware = new Dispatcher($this->middlewares, $response); $delegate = new Delegate($callback); $result = $middleware->process($request, $delegate); } return isset($result) ? $result : $callback($request); }
php
{ "resource": "" }
q250602
Complex.norm
validation
public function norm() { if ($this->original) { return $this->original->rho; } return sqrt(pow($this->float_r, 2) + pow($this->float_i, 2)); }
php
{ "resource": "" }
q250603
Complex.argument
validation
public function argument() { if ($this->original) { return $this->original->theta; } return atan2($this->float_i, $this->float_r); }
php
{ "resource": "" }
q250604
Complex.add
validation
public function add($z) { if (is_numeric($z)) { $z = new self($z, 0); } return new self($this->float_r + $z->re, $this->float_i + $z->im); }
php
{ "resource": "" }
q250605
Complex.substract
validation
public function substract($z) { if (is_numeric($z)) { $z = new self($z, 0); } return $this->add($z->negative()); }
php
{ "resource": "" }
q250606
Complex.multiply
validation
public function multiply($z) { if (is_numeric($z)) { $z = new self($z, 0); } return new self( ($this->float_r * $z->re) - ($this->float_i * $z->im), ($this->float_r * $z->im) + ($z->re * $this->float_i) ); }
php
{ "resource": "" }
q250607
Complex.divide
validation
public function divide($z) { if (is_numeric($z)) { $z = new self($z, 0); } if ($z->is_zero) { throw new \InvalidArgumentException('Cannot divide by zero!'); } $divisor = pow($z->re, 2) + pow($z->im, 2); $r = ($this->float_r * $z->re) + ($this->float_i * $z->im); $i = ($this->float_i * $z->re) - ($this->float_r * $z->im); $r = $r / $divisor; $i = $i / $divisor; return new self( $r, $i); }
php
{ "resource": "" }
q250608
Complex.equal
validation
public function equal($z) { if (is_numeric($z)) { $z = new self($z, 0); } return ($z->real == $this->float_r) && ($z->imaginary == $this->float_i); }
php
{ "resource": "" }
q250609
HttpIntegration.globals
validation
protected function globals(Configuration $config) { $cookies = $config->get('app.http.cookies', array()); $files = $config->get('app.http.files', array()); $get = $config->get('app.http.get', array()); $post = $config->get('app.http.post', array()); $server = $config->get('app.http.server', $this->server()); return array($server, $cookies, $get, $files, $post); }
php
{ "resource": "" }
q250610
HttpIntegration.resolve
validation
protected function resolve(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response) { if (class_exists('Zend\Diactoros\ServerRequestFactory')) { $response = new ZendResponse; $request = ServerRequestFactory::fromGlobals(); } $container->set('Psr\Http\Message\ServerRequestInterface', $request); return $container->set('Psr\Http\Message\ResponseInterface', $response); }
php
{ "resource": "" }
q250611
Application.handle
validation
public function handle(ServerRequestInterface $request) { $callback = new CallbackHandler(self::$container); if (static::$container->has(self::MIDDLEWARE)) { $middleware = static::$container->get(self::MIDDLEWARE); $delegate = new Delegate($callback); $result = $middleware->process($request, $delegate); } return isset($result) ? $result : $callback($request); }
php
{ "resource": "" }
q250612
Application.integrate
validation
public function integrate($integrations, ConfigurationInterface $config = null) { list($config, $container) = array($config ?: $this->config, static::$container); foreach ((array) $integrations as $item) { $integration = is_string($item) ? new $item : $item; $container = $integration->define($container, $config); } static::$container = $container; return $this; }
php
{ "resource": "" }
q250613
Application.run
validation
public function run() { // NOTE: To be removed in v1.0.0. Use "ErrorHandlerIntegration" instead. if (static::$container->has(self::ERROR_HANDLER)) { $debugger = static::$container->get(self::ERROR_HANDLER); $debugger->display(); } $request = static::$container->get(self::SERVER_REQUEST); echo (string) $this->emit($request)->getBody(); }
php
{ "resource": "" }
q250614
WhoopsErrorHandler.display
validation
public function display() { $handler = new PrettyPageHandler; error_reporting(E_ALL); $this->__call('pushHandler', array($handler)); return $this->whoops->register(); }
php
{ "resource": "" }
q250615
MiddlewareIntegration.dispatcher
validation
protected function dispatcher(ResponseInterface $response, $stack) { $dispatcher = new Dispatcher($stack, $response); if (class_exists('Zend\Stratigility\MiddlewarePipe')) { $pipe = new MiddlewarePipe; $dispatcher = new StratigilityDispatcher($pipe, $stack, $response); } return $dispatcher; }
php
{ "resource": "" }
q250616
Renderer.render
validation
public function render($template, array $data = array()) { list($file, $name) = array(null, str_replace('.', '/', $template)); foreach ((array) $this->paths as $key => $path) { $files = (array) $this->files($path); $item = $this->check($files, $path, $key, $name . '.php'); $item !== null && $file = $item; } if (is_null($file) === true) { $message = 'Template file "' . $name . '" not found.'; throw new \InvalidArgumentException((string) $message); } return $this->extract($file, $data); }
php
{ "resource": "" }
q250617
Renderer.check
validation
protected function check(array $files, $path, $source, $template) { $file = null; foreach ((array) $files as $key => $value) { $filepath = (string) str_replace($path, $source, $value); $filepath = str_replace('\\', '/', (string) $filepath); $filepath = (string) preg_replace('/^\d\//i', '', $filepath); $exists = (string) $filepath === $template; $lowercase = strtolower($filepath) === $template; ($exists || $lowercase) && $file = $value; } return $file; }
php
{ "resource": "" }
q250618
Renderer.extract
validation
protected function extract($filepath, array $data) { extract($data); ob_start(); include $filepath; $contents = ob_get_contents(); ob_end_clean(); return $contents; }
php
{ "resource": "" }
q250619
Renderer.files
validation
protected function files($path) { $directory = new \RecursiveDirectoryIterator($path); $iterator = new \RecursiveIteratorIterator($directory); $regex = new \RegexIterator($iterator, '/^.+\.php$/i', 1); return (array) array_keys(iterator_to_array($regex)); }
php
{ "resource": "" }
q250620
Dispatcher.parse
validation
protected function parse($httpMethod, $uri, $route) { $matched = preg_match($route[4], $uri, $parameters); if ($matched && ($httpMethod == $route[0] || $httpMethod == 'OPTIONS')) { $this->allowed($route[0]); array_shift($parameters); return array($route[2], $parameters, $route[3], $route[5]); } return null; }
php
{ "resource": "" }
q250621
Dispatcher.retrieve
validation
protected function retrieve(array $routes, $uri) { $routes = array_values(array_filter($routes)); if (empty($routes)) { $message = 'Route "' . $uri . '" not found'; throw new \UnexpectedValueException($message); } $route = current($routes); $route[1] = (count($route[1]) > 0) ? array_combine($route[3], $route[1]) : $route[1]; return $route; }
php
{ "resource": "" }
q250622
LeagueContainer.set
validation
public function set($id, $concrete, $share = false) { return $this->add($id, $concrete, $share); }
php
{ "resource": "" }
q250623
FontAwesomeBackend.getTag
validation
public function getTag($classNames, $color = null) { return ArrayData::create([ 'ClassNames' => $classNames, 'Color' => $color ])->renderWith(sprintf('%s\Tag', self::class)); }
php
{ "resource": "" }
q250624
FontAwesomeBackend.getClassName
validation
public function getClassName($identifier, $args = []) { if (isset($this->classes[$identifier])) { return $args ? vsprintf($this->classes[$identifier], $args) : $this->classes[$identifier]; } }
php
{ "resource": "" }
q250625
FontAwesomeBackend.getIcons
validation
public function getIcons() { // Initialise: $icons = []; // Iterate Grouped Icons: foreach ($this->getGroupedIcons() as $name => $group) { foreach ($group as $id => $icon) { if (!isset($icons[$id])) { $icons[$id] = isset($icon['name']) ? $icon['name'] : $id; } } } // Sort Icons by Key: ksort($icons); // Answer Icons: return $icons; }
php
{ "resource": "" }
q250626
FontAwesomeBackend.getGroupedIcons
validation
public function getGroupedIcons() { // Answer Cached Icons (if available): if ($icons = self::cache()->get($this->getCacheKey())) { return $icons; } // Initialise: $icons = []; // Parse Icon Source Data: $data = Yaml::parse($this->getSourceData()); // Build Icon Groups: if (isset($data['icons'])) { foreach ($data['icons'] as $icon) { foreach ($icon['categories'] as $category) { // Create Category Array: if (!isset($icons[$category])) { $icons[$category] = []; } // Create Icon Element: $icons[$category][$icon['id']] = [ 'name' => $icon['name'], 'unicode' => $icon['unicode'] ]; } } } // Sort Icons by Group: ksort($icons); // Sort Icon Groups by Name: foreach ($icons as &$group) { uasort($group, function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); } // Store Icons in Cache: self::cache()->set($this->getCacheKey(), $icons); // Answer Grouped Icons: return $icons; }
php
{ "resource": "" }
q250627
Router.retrieve
validation
public function retrieve($httpMethod, $uri) { $route = array($httpMethod, $uri); $routes = array_map(function ($route) { return array($route[0], $route[1]); }, $this->routes); $key = array_search($route, $routes); return $key !== false ? $this->routes[$key] : null; }
php
{ "resource": "" }
q250628
Router.restful
validation
public function restful($route, $class, $middlewares = array()) { $middlewares = (is_string($middlewares)) ? array($middlewares) : $middlewares; $this->add('GET', '/' . $route, $class . '@index', $middlewares); $this->add('POST', '/' . $route, $class . '@store', $middlewares); $this->add('DELETE', '/' . $route . '/:id', $class . '@delete', $middlewares); $this->add('GET', '/' . $route . '/:id', $class . '@show', $middlewares); $this->add('PATCH', '/' . $route . '/:id', $class . '@update', $middlewares); $this->add('PUT', '/' . $route . '/:id', $class . '@update', $middlewares); return $this; }
php
{ "resource": "" }
q250629
Router.prefix
validation
public function prefix($prefix = '', $namespace = '') { $namespace === '' && $namespace = (string) $this->namespace; $prefix && $prefix[0] !== '/' && $prefix = '/' . $prefix; $namespace = str_replace('\\\\', '\\', $namespace . '\\'); $this->prefix = (string) $prefix; $this->namespace = ltrim($namespace, '\\'); return $this; }
php
{ "resource": "" }
q250630
Router.parse
validation
protected function parse($route) { $route[0] = strtoupper($route[0]); $route[1] = str_replace('//', '/', $this->prefix . $route[1]); is_string($route[2]) && $route[2] = explode('@', $route[2]); is_array($route[2]) && $route[2][0] = $this->namespace . $route[2][0]; is_array($route[3]) || $route[3] = array($route[3]); return $route; }
php
{ "resource": "" }
q250631
Sortable.getSortValBeforeAll
validation
public function getSortValBeforeAll($groupingId = null) { if ($groupingId === null && $this->grpColumn) { throw new SortableException( 'groupingId may be omitted only when grpColumn is not configured.' ); } $query = (new Query()) ->select([$this->pkColumn, $this->srtColumn]) ->from($this->targetTable) ->where([ 'and', $this->grpColumn ? ['=', $this->grpColumn, $groupingId] : [], $this->skipRowsClause() ]) ->orderBy([$this->srtColumn => SORT_ASC]) ->limit(1); $result = $query->one($this->db); if ($result && $result[$this->srtColumn] == 1) { $this->rebuildSortAfter($result[$this->pkColumn], true); $sortVal = $this->getIniSortVal(); } else if ($result) { $sortVal = ceil($result[$this->srtColumn] / 2); } else $sortVal = $this->getIniSortVal(); return (int)$sortVal; }
php
{ "resource": "" }
q250632
Sortable.getSortValAfterAll
validation
public function getSortValAfterAll($groupingId = null) { if (!$groupingId === null && $this->grpColumn) { throw new SortableException( 'groupingId may be omitted only when grpColumn is not configured.' ); } $query = (new Query()) ->select($this->srtColumn) ->from($this->targetTable) ->where([ 'and', $this->grpColumn ? ['=', $this->grpColumn, $groupingId] : [], $this->skipRowsClause() ]) ->orderBy($this->srtColumn.' DESC') ->limit(1); $result = $query->one($this->db); if ($result) { $result = array_values($result); $sortVal = $result[0] + $this->sortGap; } else $sortVal = $this->getIniSortVal(); return (int)$sortVal; }
php
{ "resource": "" }
q250633
Sortable.skipRowsClause
validation
protected function skipRowsClause() { $skipClause = []; foreach ($this->skipRows as $cl => $val) { $skipClause[] = ['<>', $cl, $val]; } if (count($skipClause) > 1) array_unshift($skipClause, 'and'); return $skipClause; }
php
{ "resource": "" }
q250634
Response.withStatus
validation
public function withStatus($code, $reason = '') { // TODO: Add \InvalidArgumentException $static = clone $this; $static->code = $code; $static->reason = $reason ?: $static->codes[$code]; return $static; }
php
{ "resource": "" }
q250635
Growl.execute
validation
public function execute() { if ($this->escape !== false) { $this->options = $this->escape($this->options); } if ($this->builder !== null) { $command = $this->builder->build($this->options); exec($command); } }
php
{ "resource": "" }
q250636
Growl.buildCommand
validation
public function buildCommand() { if ($this->escape !== false) { $this->options = $this->escape($this->options); } if ($this->builder !== null) { $this->command = $this->builder->build($this->options); } return $this; }
php
{ "resource": "" }
q250637
Growl.setSafe
validation
public function setSafe($options) { if (is_string($options)) { $this->safe[] = $options; return $this; } if (is_array($options)) { foreach ($options as $key => $value) { $this->safe[] = $value; } return $this; } throw new InvalidArgumentException( 'This method expects a string or an array argument.' ); }
php
{ "resource": "" }
q250638
Growl.escape
validation
protected function escape(array $options) { $results = []; foreach ($options as $key => $value) { if (!in_array($key, $this->safe)) { $results[$key] = escapeshellarg($value); } else { $results[$key] = $value; } } return $results; }
php
{ "resource": "" }
q250639
Growl.selectBuilder
validation
protected function selectBuilder() { if (PHP_OS === 'Darwin') { if (exec('which growlnotify')) { return new GrowlNotifyBuilder; } if (exec('which terminal-notifier')) { return new TerminalNotifierBuilder; } } if (PHP_OS === 'Linux') { if (exec('which notify-send')) { return new NotifySendBuilder; } } if (PHP_OS === 'WINNT') { if (exec('where growlnotify')) { return new GrowlNotifyWindowsBuilder; } } }
php
{ "resource": "" }
q250640
Factorial.compute
validation
protected function compute($n) { $int_fact = 1; for ($i = 1; $i <= $n ; $i++) { $int_fact *= $i; } return $int_fact; }
php
{ "resource": "" }
q250641
SentryTarget.export
validation
public function export() { foreach ($this->messages as $message) { list($msg, $level, $catagory, $timestamp, $traces) = $message; $errStr = ''; $options = [ 'level' => yii\log\Logger::getLevelName($level), 'extra' => [], ]; $templateData = null; if (is_array($msg)) { $errStr = isset($msg['msg']) ? $msg['msg'] : ''; if (isset($msg['data'])) $options['extra'] = $msg['data']; } else { $errStr = $msg; } // Store debug trace in extra data $traces = array_map( function($v) { return "{$v['file']}".PHP_EOL."{$v['class']}::{$v['function']} [{$v['line']}]"; }, $traces ); if (!empty($traces)) $options['extra']['traces'] = $traces; $this->client->captureMessage( $errStr, array(), $options, false ); } }
php
{ "resource": "" }
q250642
Collection.setHttp
validation
public function setHttp(ServerRequestInterface $request, ResponseInterface $response) { $this->set('Psr\Http\Message\ServerRequestInterface', $request); return $this->set('Psr\Http\Message\ResponseInterface', $response); }
php
{ "resource": "" }
q250643
GrowlNotifyBuilder.build
validation
public function build($options) { $command = $this->path; if (isset($options['title'])) { $command .= " -t {$options['title']}"; } if (isset($options['message'])) { $command .= " -m {$options['message']}"; } if (isset($options['image'])) { $pathInfo = pathinfo($options['image']); if (isset($pathInfo['extension'])) { $command .= " --image {$options['image']}"; } else { $command .= " -a {$options['image']}"; } } if (isset($options['url'])) { $command .= " --url {$options['url']}"; } if (isset($options['sticky']) && $options['sticky'] === true) { $command .= ' -s'; } return $command; }
php
{ "resource": "" }
q250644
Collector.get
validation
public static function get(ContainerInterface $container, array $components = array(), &$globals = null) { $configuration = new Configuration; $collection = new Collection; foreach ((array) $components as $component) { $instance = self::prepare($collection, $component); $container = $instance->define($container, $configuration); } $collection->setContainer($container); // NOTE: To be removed in v1.0.0. Use Application::container instead. $globals === null || $globals['container'] = $container; return $collection; }
php
{ "resource": "" }
q250645
Collector.prepare
validation
protected static function prepare(Collection &$collection, $component) { $instance = new $component; $type = $instance->type(); if (empty($type) === false) { $parameters = array($instance->get()); $type === 'http' && $parameters = $instance->get(); $class = array($collection, 'set' . ucfirst($type)); call_user_func_array($class, $parameters); } return $instance; }
php
{ "resource": "" }
q250646
Dispatcher.push
validation
public function push($middleware) { if (is_array($middleware)) { $this->stack = array_merge($this->stack, $middleware); return $this; } $this->stack[] = $middleware; return $this; }
php
{ "resource": "" }
q250647
Dispatcher.approach
validation
protected function approach($middleware) { if ($middleware instanceof \Closure) { $object = new \ReflectionFunction($middleware); return count($object->getParameters()) === 2; } $class = (string) get_class($middleware); $object = new \ReflectionMethod($class, '__invoke'); return count($object->getParameters()) === 2; }
php
{ "resource": "" }
q250648
Dispatcher.callback
validation
protected function callback($middleware, ResponseInterface $response) { $middleware = is_string($middleware) ? new $middleware : $middleware; $callback = function ($request, $next = null) use ($middleware) { return $middleware($request, $next); }; if ($this->approach($middleware) == self::SINGLE_PASS) { $callback = function ($request, $next = null) use ($middleware, $response) { return $middleware($request, $response, $next); }; } return $callback; }
php
{ "resource": "" }
q250649
Dispatcher.resolve
validation
protected function resolve($index) { $callback = null; $stack = $this->stack; if (isset($this->stack[$index])) { $item = $stack[$index]; $next = $this->resolve($index + 1); $callback = function ($request) use ($item, $next) { return $item->process($request, $next); }; } return new Delegate($callback); }
php
{ "resource": "" }
q250650
Dispatcher.transform
validation
protected function transform($middleware, $wrappable = true) { if (is_a($middleware, Application::MIDDLEWARE) === false) { $approach = (boolean) $this->approach($middleware); $response = $approach === self::SINGLE_PASS ? $this->response : null; $wrapper = new CallableMiddlewareWrapper($middleware, $response); $middleware = $wrappable === true ? $wrapper : $middleware; } return $middleware; }
php
{ "resource": "" }
q250651
PhrouteDispatcher.collect
validation
protected function collect() { $collector = new RouteCollector; foreach ($this->router->routes() as $route) { $collector->addRoute($route[0], $route[1], $route[2]); } return $collector->getData(); }
php
{ "resource": "" }
q250652
PhrouteDispatcher.exceptions
validation
protected function exceptions(\Exception $exception, $uri) { $interface = 'Phroute\Phroute\Exception\HttpRouteNotFoundException'; $message = (string) $exception->getMessage(); is_a($exception, $interface) && $message = 'Route "' . $uri . '" not found'; throw new \UnexpectedValueException((string) $message); }
php
{ "resource": "" }
q250653
Uri.getAuthority
validation
public function getAuthority() { $authority = $this->host; if ($this->host !== '' && $this->user !== null) { $authority = $this->user . '@' . $authority; $authority = $authority . ':' . $this->port; } return $authority; }
php
{ "resource": "" }
q250654
Uri.instance
validation
public static function instance(array $server) { $secure = isset($server['HTTPS']) ? $server['HTTPS'] : 'off'; $http = $secure === 'off' ? 'http' : 'https'; $url = $http . '://' . $server['SERVER_NAME']; $url .= (string) $server['SERVER_PORT']; return new Uri($url . $server['REQUEST_URI']); }
php
{ "resource": "" }
q250655
NormalDistribution.variance
validation
public function variance() { $float_variance = pow($this->float_sigma, 2); if ($this->int_precision) { return round($float_variance, $this->int_precision); } return $float_variance; }
php
{ "resource": "" }
q250656
NormalDistribution.precision
validation
public function precision($n) { if (!is_numeric($n) || $n < 0) { throw new \InvalidArgumentException('Precision must be positive number'); } $this->int_precision = (integer) $n; }
php
{ "resource": "" }
q250657
NormalDistribution.max
validation
public function max() { $float_max = 1 / ($this->float_sigma * sqrt(2 * pi())); if ($this->int_precision) { return round($float_max, $this->int_precision); } return $float_max; }
php
{ "resource": "" }
q250658
NormalDistribution.fwhm
validation
public function fwhm() { $float_fwhm = 2 * sqrt(2 * log(2)) * $this->float_sigma; if ($this->int_precision) { return round($float_fwhm, $this->int_precision); } return $float_fwhm; }
php
{ "resource": "" }
q250659
NormalDistribution.f
validation
public function f($x) { if (!is_numeric($x)) { throw new \InvalidArgumentException('x variable must be numeric value.'); } $float_fx = exp(-0.5 * pow(($x - $this->float_mu) / $this->float_sigma, 2)) / ($this->float_sigma * sqrt(2 * pi())); if ($this->int_precision) { return round($float_fx, $this->int_precision); } return $float_fx; }
php
{ "resource": "" }
q250660
NormalDistribution.samples
validation
public function samples($amount) { if (!is_numeric($amount) || $amount < 1) { throw new \InvalidArgumentException('Amount of samples must be greater or equal to one'); } $arr = array(); for ($i = 1; $i <= $amount; $i++) { $r = new Random(); $float_u = $r->get(); $float_v = $r->get(); $double_x = $this->float_sigma * sqrt(-2 * log($float_u)) * cos(2 * pi() * $float_v) + $this->float_mu; if ($this->int_precision) { $arr[] = round($double_x, $this->int_precision); } else { $arr[] = $double_x; } } return $arr; }
php
{ "resource": "" }
q250661
FontIconField.search
validation
public function search(HTTPRequest $request) { // Detect Ajax: if (!$request->isAjax()) { return; } // Initialise: $data = []; // Filter Icons: if ($term = $request->getVar('term')) { // Create Groups Array: $groups = []; // Iterate Icon Groups: foreach ($this->backend->getGroupedIcons() as $group => $icons) { // Create Children Array: $children = []; // Iterate Icons in Group: foreach ($icons as $id => $icon) { if (stripos($id, $term) !== false) { $children[] = $this->getResultData($this->getIconData($id)); } } // Create Result Group (if children defined): if (!empty($children)) { $groups[] = [ 'text' => $group, 'children' => $children ]; } } // Define Results: $data['results'] = $groups; } // Answer JSON Response: return $this->respond($data); }
php
{ "resource": "" }
q250662
Stream.getContents
validation
public function getContents() { if (is_null($this->stream) || ! $this->isReadable()) { $message = 'Could not get contents of stream'; throw new \RuntimeException($message); } return stream_get_contents($this->stream); }
php
{ "resource": "" }
q250663
Stream.getMetadata
validation
public function getMetadata($key = null) { isset($this->stream) && $this->meta = stream_get_meta_data($this->stream); $metadata = isset($this->meta[$key]) ? $this->meta[$key] : null; return is_null($key) ? $this->meta : $metadata; }
php
{ "resource": "" }
q250664
Stream.getSize
validation
public function getSize() { if (is_null($this->size) === true) { $stats = fstat($this->stream); $this->size = $stats['size']; } return $this->size; }
php
{ "resource": "" }
q250665
Stream.write
validation
public function write($string) { if (! $this->isWritable()) { $message = 'Stream is not writable'; throw new \RuntimeException($message); } $this->size = null; return fwrite($this->stream, $string); }
php
{ "resource": "" }
q250666
Stats.f
validation
public function f() { if(is_null($this->arr_f)){ $arr = $this->frequency(); array_walk( $arr, function(&$v, $k, $n){ $v = $v / $n; }, count($this) ); $this->arr_f = $arr; } return $this->arr_f; }
php
{ "resource": "" }
q250667
TerminalNotifierBuilder.build
validation
public function build($options) { $command = $this->path; if (isset($options['title'])) { $command .= " -title {$options['title']}"; } if (isset($options['subtitle'])) { $command .= " -subtitle {$options['subtitle']}"; } if (isset($options['message'])) { $command .= " -message {$options['message']}"; } if (isset($options['image'])) { $command .= " -appIcon {$options['image']}"; } if (isset($options['contentImage'])) { $command .= " -contentImage {$options['contentImage']}"; } if (isset($options['url'])) { $command .= " -open {$options['url']}"; } return $command; }
php
{ "resource": "" }
q250668
TwigRenderer.render
validation
public function render($template, array $data = array(), $extension = 'twig') { $file = $template . '.' . $extension; return $this->twig->render($file, $data); }
php
{ "resource": "" }
q250669
FontIconExtension.updateCMSFields
validation
public function updateCMSFields(FieldList $fields) { // Insert Icon Tab: $fields->insertAfter( Tab::create( 'Icon', $this->owner->fieldLabel('Icon') ), 'Main' ); // Create Icon Fields: $fields->addFieldsToTab( 'Root.Icon', [ FontIconField::create( 'FontIcon', $this->owner->fieldLabel('FontIcon') ), ColorField::create( 'FontIconColor', $this->owner->fieldLabel('FontIconColor') ) ] ); }
php
{ "resource": "" }
q250670
FontIconExtension.getFontIconClassNames
validation
public function getFontIconClassNames() { $classes = []; if ($this->owner->FontIcon) { if ($this->owner->FontIconListItem) { $classes[] = $this->backend->getClassName('list-item'); } if ($this->owner->FontIconFixedWidth) { $classes[] = $this->backend->getClassName('fixed-width'); } $classes[] = $this->backend->getClassName('icon', [$this->owner->FontIcon]); } return $classes; }
php
{ "resource": "" }
q250671
FontIconExtension.getFontIconTag
validation
public function getFontIconTag() { if ($this->owner->hasFontIcon()) { return $this->backend->getTag( $this->owner->FontIconClass, $this->owner->FontIconColor ); } }
php
{ "resource": "" }
q250672
FastRouteRouter.routes
validation
public function routes() { $routes = array_merge($this->routes, $this->collector->getData()); return function (RouteCollector $collector) use ($routes) { foreach (array_filter($routes) as $route) { list($method, $uri, $handler) = (array) $route; $collector->addRoute($method, $uri, $handler); } }; }
php
{ "resource": "" }
q250673
RandomComplex.random
validation
protected static function random($float_min, $float_max) { if ($float_max >= 0) { $r = new Random(); while (true) { $float_prov = $float_max * $r->get(); if ($float_prov >= $float_min) { return $float_prov; } } } else { $r = new Random(); while (true) { $float_prov = $float_min * $r->get(); if ($float_prov <= $float_max) { return $float_prov; } } } }
php
{ "resource": "" }
q250674
RandomComplex.checkOrder
validation
protected static function checkOrder($float_min, $float_max) { if (!is_numeric($float_min) && !is_numeric($float_max)) { throw new \InvalidArgumentException('Min and max values must be valid numbers.'); } if ($float_min >= $float_max) { throw new \InvalidArgumentException('Max value must be greater than min value!'); } }
php
{ "resource": "" }
q250675
RandomComplex.rho
validation
public function rho($float_min, $float_max) { self::checkOrder($float_min, $float_max); if ($float_min < 0 || $float_max < 0) { throw new \InvalidArgumentException('Rho value must be a positive number!'); } if ($this->r || $this->i) { throw new \RuntimeException('You cannot set rho value, because algebraic form is in use.'); } $this->rho = new \stdClass(); $this->rho->min = $float_min; $this->rho->max = $float_max; return $this; }
php
{ "resource": "" }
q250676
RandomComplex.theta
validation
public function theta($float_min, $float_max) { self::checkOrder($float_min, $float_max); if ($this->r || $this->i) { throw new \RuntimeException('You cannot set theta value, because algebraic form is in use.'); } $this->theta = new \stdClass(); $this->theta->min = $float_min; $this->theta->max = $float_max; return $this; }
php
{ "resource": "" }
q250677
RandomComplex.get
validation
public function get() { if ($this->r || $this->i) { if (!is_object($this->i)) { return new Complex( self::random($this->r->min, $this->r->max), 0 ); } if (!is_object($this->r)) { return new Complex( 0, self::random($this->i->min, $this->i->max) ); } return new Complex( self::random($this->r->min, $this->r->max), self::random($this->i->min, $this->i->max) ); } if ($this->rho || $this->theta) { if (!is_object($this->theta)) { return new Complex( self::random($this->rho->min, $this->rho->max), 0, Complex::TRIGONOMETRIC ); } if (!is_object($this->rho)) { return new Complex( 0, self::random($this->theta->min, $this->theta->max), Complex::TRIGONOMETRIC ); } return new Complex( self::random($this->rho->min, $this->rho->max), self::random($this->theta->min, $this->theta->max), Complex::TRIGONOMETRIC ); } }
php
{ "resource": "" }
q250678
RandomComplex.getMany
validation
public function getMany($n) { if (!is_integer($n) || $n < 2) { throw new \InvalidArgumentException('You must take 2 or more items in this case.'); } $arr_out = array(); for ($i = 0; $i < $n; $i++) { $arr_out[] = $this->get(); } return $arr_out; }
php
{ "resource": "" }
q250679
RandomComplex.reset
validation
public function reset() { $this->rho = null; $this->theta = null; $this->r = null; $this->i = null; return $this; }
php
{ "resource": "" }
q250680
Container.alias
validation
public function alias($id, $original) { $this->instances[$id] = $this->get($original); return $this; }
php
{ "resource": "" }
q250681
Container.value
validation
protected function value($name) { $object = isset($this->instances[$name]) ? $this->get($name) : null; $exists = ! $object && $this->extra->has($name) === true; return $exists === true ? $this->extra->get($name) : $object; }
php
{ "resource": "" }
q250682
Random.get
validation
public function get() { if ($this->range->as_integer) { return mt_rand($this->range->min, $this->range->max); } else { return mt_rand(0, mt_getrandmax()) / mt_getrandmax(); } }
php
{ "resource": "" }
q250683
Random.getManyWithoutReplacement
validation
public function getManyWithoutReplacement($n) { if (!is_integer($n) || $n < 2) { throw new \InvalidArgumentException('You must take 2 or more items in this case.'); } if ($this->range->as_integer) { $arr_range = range($this->range->min, $this->range->max); $max_takable = count($arr_range); shuffle($arr_range); if ($n > $max_takable) { throw new \OutOfRangeException( sprintf( 'Cannot take without replacement more than available items into range [%d;%d]', $this->range->min, $this->range->max ) ); } elseif ($n == $max_takable) { return array_values($arr_range); } else { return array_slice($arr_range, 0, $n); } } else { $arr_out = array(); while (count($arr_out) < $n) { $r = $this->get(); if (!in_array($r, $arr_out)) { $arr_out[] = $r; } } return $arr_out; } }
php
{ "resource": "" }
q250684
JetPackTrait.setPackOptions
validation
public function setPackOptions(Container $app) { foreach ($this->packOptions as $key => &$value) { $key = $this->_ns($key); if (isset($app[$key])) { $value = $app[$key]; } } }
php
{ "resource": "" }
q250685
JetPackTrait.getName
validation
public function getName() { static $names = []; $me = get_class($this); if (empty($names[$me])) { $names[$me] = $this->getReflector()->getShortName(); $suffix = defined('static::PACK_SUFFIX') ? static::PACK_SUFFIX : 'Pack'; if (strrpos($names[$me], $suffix) == (strlen($names[$me]) - strlen($suffix))) { $names[$me] = substr($names[$me], 0, strlen($names[$me]) - strlen($suffix)); } } return $names[$me]; }
php
{ "resource": "" }
q250686
JetPackTrait.getEntityMappings
validation
public function getEntityMappings(Container $app) { static $mappings = []; $me = get_class($this); if (empty($mappings[$me])) { $subns = $this->packOptions['entity_subnamespace']; $subns = trim($subns, '\\'); $simple = $this->packOptions['entity_use_simple_annotation']; $ns = $this->getReflector()->getNamespaceName() . '\\' . $subns; $subpath = str_replace('\\', '/', $subns); $path = dirname($this->getReflector()->getFileName()) . '/' . $subpath; if (is_dir($path)) { $mappings[$me] = [ 'type' => 'annotation', 'namespace' => $ns, 'path' => $path, 'use_simple_annotation_reader' => $simple, ]; } } if (empty($mappings[$me])) { return []; } return [$mappings[$me]]; }
php
{ "resource": "" }
q250687
JetPackTrait.getConfigsPath
validation
public function getConfigsPath(Container $app) { static $paths = []; $me = get_class($this); if (empty($paths[$me])) { $subpath = $this->packOptions['configs_subpath']; $paths[$me] = dirname($this->getReflector()->getFileName()) . '/' . $subpath; } return $paths[$me]; }
php
{ "resource": "" }
q250688
JetPackTrait.getSymlinks
validation
public function getSymlinks(Container $app) { $symlinks = []; if ($this->getPublicPath($app)) { $symlinks[$this->getPublicPath($app)] = 'packs/' . $this->_ns(); } return $symlinks; }
php
{ "resource": "" }
q250689
JetPackTrait.getPackPath
validation
public function getPackPath(Container $app) { static $paths = []; $me = get_class($this); if (empty($paths[$me])) { $paths[$me] = dirname($this->getReflector()->getFileName()); } return $paths[$me]; }
php
{ "resource": "" }
q250690
AbstractDispatcher.allowed
validation
protected function allowed($method) { if (in_array($method, $this->allowed) === false) { $message = 'Used method is not allowed'; throw new \UnexpectedValueException($message); } return true; }
php
{ "resource": "" }
q250691
Rule.pathExtract
validation
protected function pathExtract(): array { $regExp = []; $path = $this->path; if (\is_array($this->path)) { $regExp = \array_pop($this->path); $path = \array_pop($this->path); } return [$path, $regExp]; }
php
{ "resource": "" }
q250692
Dlstats.logDLStatDetails
validation
protected function logDLStatDetails() { //Host / Page ID ermitteln $pageId = $GLOBALS['objPage']->id; // ID der grad aufgerufenden Seite. $pageHost = \Environment::get('host'); // Host der grad aufgerufenden Seite. if (isset($GLOBALS['TL_CONFIG']['dlstatdets']) && (bool) $GLOBALS['TL_CONFIG']['dlstatdets'] === true ) { //Maximum details for year & month statistic $username = ''; $strCookie = 'FE_USER_AUTH'; $hash = sha1(session_id() . (!$GLOBALS['TL_CONFIG']['disableIpCheck'] ? $this->IP : '') . $strCookie); if (\Input::cookie($strCookie) == $hash) { $qs = \Database::getInstance()->prepare("SELECT pid, tstamp, sessionID, ip FROM `tl_session` WHERE `hash`=? AND `name`=?") ->execute($hash, $strCookie); if ($qs->next() && $qs->sessionID == session_id() && ($GLOBALS['TL_CONFIG']['disableIpCheck'] || $qs->ip == $this->IP) && ($qs->tstamp + $GLOBALS['TL_CONFIG']['sessionTimeout']) > time()) { $qm = \Database::getInstance()->prepare("SELECT `username` FROM `tl_member` WHERE id=?") ->execute($qs->pid); if ($qm->next()) { $username = $qm->username; } } // if } // if \Database::getInstance()->prepare("INSERT INTO `tl_dlstatdets` %s") ->set(array('tstamp' => time(), 'pid' => $this->_statId, 'ip' => $this->dlstatsAnonymizeIP(), 'domain' => $this->dlstatsAnonymizeDomain(), 'username' => $username, 'page_host' => $pageHost, 'page_id' => $pageId, 'browser_lang' => $this->dlstatsGetLang() ) ) ->execute(); } else { //Minimum details for year & month statistic \Database::getInstance()->prepare("INSERT INTO `tl_dlstatdets` %s") ->set(array('tstamp' => time(), 'pid' => $this->_statId ) ) ->execute(); } }
php
{ "resource": "" }
q250693
SearchAbstract.query
validation
public function query($index, array $filters = null, array $queries = null, array $fieldWeights = null, $limit = 20, $offset = 0 ) { $sphinxClient = $this->getSphinxClient(); $sphinxClient->SetLimits($offset, $limit); if (null !== $filters) { foreach ($filters as $filter) { if (!isset($filter['key'])) { // Filtro existe mas sem key } if ( array_key_exists('min', $filter) && array_key_exists('max', $filter) ) { $sphinxClient->SetFilterRange( $filter['key'], (integer) $filter['min'], (integer) $filter['max'] ); } else { if (!isset($filter['values']) || !is_array($filter['values'])) { //Filtro existe mas sem valor; } $sphinxClient->SetFilter( $filter['key'], $filter['values'] ); } } } if (null !== $queries) { foreach ($queries as $key => $queryInfo) { $query = $this->implodeQueryValues($queryInfo); if (array_key_exists('countableAttributes', $queryInfo)) { $array = $queryInfo['countableAttributes']; if (!is_array($array)) { $array = [$array]; } $sphinxClient->addFacetedQuery($query, $index, $array); } else { $sphinxClient->AddQuery($query, $index); } } } if (null !== $fieldWeights) { $sphinxClient->SetFieldWeights($fieldWeights); } $result = $this->getResult($sphinxClient); return $result; }
php
{ "resource": "" }
q250694
SearchAbstract.getCollection
validation
public function getCollection($index, array $filters = null, array $queries = null, array $fieldWeights = null, $limit = 20, $offset = 0, $countableAttributes = null ) { $result = $this->query($index, $filters, $queries, $fieldWeights, $limit, $offset); if (is_array($result)) { $i = 0; if ($countableAttributes) { foreach ($countableAttributes as $attributeName) { $i++; $result[0]['attributes']['countable'][$attributeName] = new CountableCollection($result[$i], $attributeName); } } for ($l = 1; $l <= $i; $l++) { unset($result[$l]); } $collection = $this->factoryCollection($result); return $collection; } }
php
{ "resource": "" }
q250695
Parser.doParse
validation
protected function doParse(StringReader $string) { $val = null; // May be : or ; as a terminator, depending on what the data // type is. $type = substr($string->read(2), 0, 1); switch ($type) { case 'a': // Associative array: a:length:{[index][value]...} $count = (int)$string->readUntil(':'); // Eat the opening "{" of the array. $string->read(1); $val= []; for($i=0; $i < $count; $i++) { $array_key = $this->doParse($string); $array_value = $this->doParse($string); $val[$array_key] = $array_value; } // Eat "}" terminating the array. $string->read(1); break; case 'O': // Object: O:length:"class":length:{[property][value]...} $len = (int)$string->readUntil(':'); // +2 for quotes $class = $string->read(2 + $len); // Eat the separator $string->read(1); // Do the properties. // Initialise with the original name of the class. $properties = ['__class_name' => $class]; // Read the number of properties. $len = (int)$string->readUntil(':'); // Eat "{" holding the properties. $string->read(1); for($i=0; $i < $len; $i++) { $prop_key = $this->doParse($string); $prop_value = $this->doParse($string); // Strip the protected and private prefixes from the names. // Maybe replace them with something more informative, such as "protected:" and "private:"? if (substr($prop_key, 0, strlen(self::PROTECTED_PREFIX)) == self::PROTECTED_PREFIX) { $prop_key = substr($prop_key, strlen(self::PROTECTED_PREFIX)); } if (substr($prop_key, 0, 1) == "\0") { list(, $private_class, $private_property_name) = explode("\0", $prop_key); $prop_key = $private_property_name; } $properties[$prop_key] = $prop_value; } // Eat "}" terminating properties. $string->read(1); $val = (object)$properties; break; case 's': $len = (int)$string->readUntil(':'); $val = $string->read($len + 2); // Eat the separator $string->read(1); break; case 'i': $val = (int)$string->readUntil(';'); break; case 'd': $val = (float)$string->readUntil(';'); break; case 'b': // Boolean is 0 or 1 $bool = $string->read(2); $val = substr($bool, 0, 1) == '1'; break; case 'N': $val = null; break; default: throw new \Exception(sprintf('Unable to unserialize type "%s"', $type)); } return $val; }
php
{ "resource": "" }
q250696
QueryAbstract.getQueries
validation
public function getQueries() { $array = []; foreach ($this->getKeywords() as $keyword) { $value = $keyword->getData(); if ($this->getCountableAttributes()) { $value['countableAttributes'] = $this->getCountableAttributes(); } $array[] = $value; } return $array; }
php
{ "resource": "" }
q250697
QueryAbstract.getOffSet
validation
public function getOffSet() { if ($this->getPaginator()) { return $this->getPaginator()->getOffset(); } else { $offset = $this->get('offset'); if (!$offset) { $offset = 0; } return $offset; } }
php
{ "resource": "" }
q250698
QueryAbstract.addCountableAttribute
validation
public function addCountableAttribute($attribute) { if (empty($attribute)) { return false; } if (in_array($attribute, $this->getCountableAttributes(), true)) { return false; } $this->addToArrayValue('countableAttributes', $attribute); return $this; }
php
{ "resource": "" }
q250699
RouteServiceProvider.mapAdminRoutes
validation
private function mapAdminRoutes() { $this->adminGroup(function () { $this->name('foundation.')->group(function () { Routes\Admin\DashboardRoute::register(); Routes\Admin\SettingsRoutes::register(); Routes\Admin\SystemRoutes::register(); }); }); }
php
{ "resource": "" }