_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q246600
InputGeneratorTrait.createUrlStatements
validation
protected function createUrlStatements(Operation $operation, $queryParamVariable) { $urlVariable = new Expr\Variable('url'); // url = /path $statements = [ new Expr\Assign($urlVariable, new Scalar\String_($operation->getPath())) ]; if ($operation->getOperation()->getParameters()) { foreach ($operation->getOperation()->getParameters() as $parameter) { if ($parameter instanceof Reference) { $parameter = $this->resolveParameter($parameter); } if ($parameter instanceof PathParameterSubSchema) { // $url = str_replace('{param}', $param, $url) $statements[] = new Expr\Assign($urlVariable, new Expr\FuncCall(new Name('str_replace'), [ new Arg(new Scalar\String_('{' . $parameter->getName() . '}')), new Arg(new Expr\FuncCall(new Name('urlencode'), [ new Arg(new Expr\Variable(Inflector::camelize($parameter->getName()))), ])), new Arg($urlVariable) ])); } } } // url = url . ? . $queryParam->buildQueryString $statements[] = new Expr\Assign($urlVariable, new Expr\BinaryOp\Concat( $urlVariable, new Expr\BinaryOp\Concat( new Scalar\String_('?'), new Expr\MethodCall($queryParamVariable, 'buildQueryString', [new Arg(new Expr\Variable('parameters'))]) ) )); return [$statements, $urlVariable]; }
php
{ "resource": "" }
q246601
InputGeneratorTrait.createBodyStatements
validation
protected function createBodyStatements(Operation $operation, $queryParamVariable, Context $context) { $bodyParameter = null; $bodyVariable = new Expr\Variable('body'); $parameterKey = 0; if ($operation->getOperation()->getParameters()) { foreach ($operation->getOperation()->getParameters() as $key => $parameter) { if ($parameter instanceof BodyParameter) { $bodyParameter = $parameter; $parameterKey = $key; } } } if (null === $bodyParameter) { // $body = $queryParam->buildFormDataString($parameters); return [[ new Expr\Assign($bodyVariable, new Expr\MethodCall($queryParamVariable, 'buildFormDataString', [new Arg(new Expr\Variable('parameters'))])) ], $bodyVariable]; } // $body = $this->serializer->serialize($parameter); if ($bodyParameter->getSchema() instanceof Reference || $context->getRegistry()->hasClass($operation->getReference() . '/parameters/' . $parameterKey)) { return [ [ new Expr\Assign( $bodyVariable, new Expr\MethodCall( new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'), 'serialize', [ new Arg(new Expr\Variable(Inflector::camelize($bodyParameter->getName()))), new Arg(new Scalar\String_('json')) ] ) ) ], $bodyVariable ]; } // $body = $parameter return [[ new Expr\Assign($bodyVariable, new Expr\Variable(Inflector::camelize($bodyParameter->getName()))) ], $bodyVariable]; }
php
{ "resource": "" }
q246602
InputGeneratorTrait.createHeaderStatements
validation
protected function createHeaderStatements(Operation $operation, $queryParamVariable) { $headerVariable = new Expr\Variable('headers'); $headers = [ new Expr\ArrayItem( new Scalar\String_($operation->getHost()), new Scalar\String_('Host') ), ]; $produces = $operation->getOperation()->getProduces(); if ($produces && in_array("application/json", $produces)) { $headers[] = new Expr\ArrayItem( new Expr\Array_( [ new Expr\ArrayItem( new Scalar\String_("application/json") ), ] ), new Scalar\String_('Accept') ); } $consumes = $operation->getOperation()->getProduces(); if ($operation->getOperation()->getParameters() && $consumes) { $bodyParameters = array_filter( $operation->getOperation()->getParameters(), function ($parameter) { return $parameter instanceof BodyParameter; } ); if (count($bodyParameters) > 0 && in_array("application/json", $consumes)) { $headers[] = new Expr\ArrayItem( new Scalar\String_("application/json"), new Scalar\String_('Content-Type') ); } } return [ [ new Expr\Assign( $headerVariable, new Expr\FuncCall(new Name('array_merge'), [ new Arg( new Expr\Array_( $headers ) ), new Arg(new Expr\MethodCall($queryParamVariable, 'buildHeaders', [new Arg(new Expr\Variable('parameters'))])) ]) ) ], $headerVariable ]; }
php
{ "resource": "" }
q246603
JaneOpenApi.createContext
validation
public function createContext(Registry $registry, $name) { $schemas = array_values($registry->getSchemas()); /** @var Schema $schema */ foreach ($schemas as $schema) { $openApiSpec = $this->schemaParser->parseSchema($schema->getOrigin()); $this->chainGuesser->guessClass($openApiSpec, $schema->getRootName(), $schema->getOrigin() . '#', $registry); $schema->setParsed($openApiSpec); } foreach ($registry->getSchemas() as $schema) { foreach ($schema->getClasses() as $class) { $properties = $this->chainGuesser->guessProperties($class->getObject(), $schema->getRootName(), $class->getReference(), $registry); foreach ($properties as $property) { $property->setType($this->chainGuesser->guessType($property->getObject(), $property->getName(), $property->getReference(), $registry)); } $class->setProperties($properties); } } return new Context($registry); }
php
{ "resource": "" }
q246604
JaneOpenApi.generate
validation
public function generate(Registry $registry) { /** @var OpenApi $openApi */ $context = $this->createContext($registry, 'Client'); $files = []; foreach ($registry->getSchemas() as $schema) { $context->setCurrentSchema($schema); $files = array_merge($files, $this->modelGenerator->generate($schema, $schema->getRootName(), $context)); $files = array_merge($files, $this->normalizerGenerator->generate($schema, $schema->getRootName(), $context)); $clients = $this->clientGenerator->generate($schema->getParsed(), $schema->getNamespace(), $context, $schema->getOrigin() . '#'); foreach ($clients as $node) { $files[] = new File($schema->getDirectory() . DIRECTORY_SEPARATOR . 'Resource' . DIRECTORY_SEPARATOR . $node->stmts[2]->name . '.php', $node, ''); } } return $files; }
php
{ "resource": "" }
q246605
JaneOpenApi.fix
validation
protected function fix($directory) { if (!class_exists('PhpCsFixer\Config')) { return; } /** @var Config $fixerConfig */ $fixerConfig = $this->fixerConfig; if (null === $fixerConfig) { $fixerConfig = Config::create() ->setRiskyAllowed(true) ->setRules( array( '@Symfony' => true, 'array_syntax' => array('syntax' => 'short'), 'simplified_null_return' => false, 'ordered_imports' => true, 'phpdoc_order' => true, 'binary_operator_spaces' => array('align_equals'=>true), 'concat_space' => false, 'yoda_style' => false, 'header_comment' => [ 'header' => <<<EOH This file has been auto generated by Jane, Do no edit it directly. EOH , ] ) ); } $resolverOptions = array('allow-risky' => true); $resolver = new ConfigurationResolver($fixerConfig, $resolverOptions, $directory, new ToolInfo()); $finder = new Finder(); $finder->in($directory); $fixerConfig->setFinder($finder); $runner = new Runner( $resolver->getConfig()->getFinder(), $resolver->getFixers(), new NullDiffer(), null, new ErrorsManager(), new Linter(), false, new NullCacheManager() ); return $runner->fix(); }
php
{ "resource": "" }
q246606
Recorder.paintPass
validation
public function paintPass($message) { parent::paintPass($message); $this->results[] = new SimpleResultOfPass(parent::getTestList(), $message); }
php
{ "resource": "" }
q246607
Recorder.paintFail
validation
public function paintFail($message) { parent::paintFail($message); $this->results[] = new SimpleResultOfFail(parent::getTestList(), $message); }
php
{ "resource": "" }
q246608
Recorder.paintException
validation
public function paintException($message) { parent::paintException($message); $this->results[] = new SimpleResultOfException(parent::getTestList(), $message); }
php
{ "resource": "" }
q246609
SimpleAttachment.asMime
validation
public function asMime() { $part = 'Content-Disposition: form-data; '; $part .= 'name="' . $this->key . '"; '; $part .= 'filename="' . $this->filename . '"'; $part .= "\r\nContent-Type: " . $this->deduceMimeType(); $part .= "\r\n\r\n" . $this->content; return $part; }
php
{ "resource": "" }
q246610
SimpleAttachment.isOnlyAscii
validation
protected function isOnlyAscii($ascii) { for ($i = 0, $length = strlen($ascii); $i < $length; $i++) { if (ord($ascii[$i]) > 127) { return false; } } return true; }
php
{ "resource": "" }
q246611
SimpleEncoding.add
validation
public function add($key, $value) { if ($value === false) { return; } if (is_array($value)) { foreach ($value as $item) { $this->addPair($key, $item); } } else { $this->addPair($key, $value); } }
php
{ "resource": "" }
q246612
SimpleEncoding.attach
validation
public function attach($key, $content, $filename) { $this->request[] = new SimpleAttachment($key, $content, $filename); }
php
{ "resource": "" }
q246613
SimpleEncoding.merge
validation
public function merge($query) { if (is_object($query)) { $this->request = array_merge($this->request, $query->getAll()); } elseif (is_array($query)) { foreach ($query as $key => $value) { $this->add($key, $value); } } }
php
{ "resource": "" }
q246614
SimpleEncoding.getValue
validation
public function getValue($key) { $values = array(); foreach ($this->request as $pair) { if ($pair->isKey($key)) { $values[] = $pair->getValue(); } } if (count($values) == 0) { return false; } elseif (count($values) == 1) { return $values[0]; } else { return $values; } }
php
{ "resource": "" }
q246615
SimpleTagBuilder.createTag
validation
public function createTag($name, $attributes) { static $map = array( 'a' => 'SimpleAnchorTag', 'title' => 'SimpleTitleTag', 'base' => 'SimpleBaseTag', 'button' => 'SimpleButtonTag', 'textarea' => 'SimpleTextAreaTag', 'option' => 'SimpleOptionTag', 'label' => 'SimpleLabelTag', 'form' => 'SimpleFormTag', 'frame' => 'SimpleFrameTag' ); $attributes = $this->keysToLowerCase($attributes); if (array_key_exists($name, $map)) { $tag_class = $map[$name]; return new $tag_class($attributes); } elseif ($name === 'select') { return $this->createSelectionTag($attributes); } elseif ($name === 'input') { return $this->createInputTag($attributes); } return new SimpleTag($name, $attributes); }
php
{ "resource": "" }
q246616
SimpleTagBuilder.createInputTag
validation
protected function createInputTag($attributes) { if (! isset($attributes['type'])) { return new SimpleTextTag($attributes); } $type = strtolower(trim($attributes['type'])); $map = array( 'submit' => 'SimpleSubmitTag', 'image' => 'SimpleImageSubmitTag', 'checkbox' => 'SimpleCheckboxTag', 'radio' => 'SimpleRadioButtonTag', 'text' => 'SimpleTextTag', 'hidden' => 'SimpleTextTag', 'password' => 'SimpleTextTag', 'file' => 'SimpleUploadTag' ); if (array_key_exists($type, $map)) { $tag_class = $map[$type]; return new $tag_class($attributes); } return false; }
php
{ "resource": "" }
q246617
SimpleTagBuilder.keysToLowerCase
validation
protected function keysToLowerCase($map) { $lower = array(); foreach ($map as $key => $value) { $lower[strtolower($key)] = $value; } return $lower; }
php
{ "resource": "" }
q246618
SimpleTag.getAttribute
validation
public function getAttribute($label) { $label = strtolower($label); if (! isset($this->attributes[$label])) { return false; } return (string) $this->attributes[$label]; }
php
{ "resource": "" }
q246619
SimpleTextAreaTag.wrapIsEnabled
validation
public function wrapIsEnabled() { if ($this->getAttribute('cols')) { $wrap = $this->getAttribute('wrap'); if (($wrap === 'physical') || ($wrap === 'hard')) { return true; } } return false; }
php
{ "resource": "" }
q246620
SimpleTextAreaTag.wrap
validation
protected function wrap($text) { $text = str_replace("\r\r\n", "\r\n", str_replace("\n", "\r\n", $text)); $text = str_replace("\r\n\n", "\r\n", str_replace("\r", "\r\n", $text)); if (strncmp($text, "\r\n", strlen("\r\n")) == 0) { $text = substr($text, strlen("\r\n")); } if ($this->wrapIsEnabled()) { return wordwrap( $text, (integer) $this->getAttribute('cols'), "\r\n"); } return $text; }
php
{ "resource": "" }
q246621
SimpleSelectionTag.setValue
validation
public function setValue($value) { for ($i = 0, $count = count($this->options); $i < $count; $i++) { if ($this->options[$i]->isValue($value)) { $this->choice = $i; return true; } } return false; }
php
{ "resource": "" }
q246622
SimpleSelectionTag.getValue
validation
public function getValue() { if ($this->choice === false) { return $this->getDefault(); } return $this->options[$this->choice]->getValue(); }
php
{ "resource": "" }
q246623
MultipleSelectionTag.setValue
validation
public function setValue($desired) { $achieved = array(); foreach ($desired as $value) { $success = false; for ($i = 0, $count = count($this->options); $i < $count; $i++) { if ($this->options[$i]->isValue($value)) { $achieved[] = $this->options[$i]->getValue(); $success = true; break; } } if (! $success) { return false; } } $this->values = $achieved; return true; }
php
{ "resource": "" }
q246624
SimpleOptionTag.isValue
validation
public function isValue($compare) { $compare = trim($compare); if (trim($this->getValue()) == $compare) { return true; } return trim(strip_tags($this->getContent())) == $compare; }
php
{ "resource": "" }
q246625
SimpleRadioButtonTag.setValue
validation
public function setValue($value) { if ($value === false) { return parent::setValue($value); } if ($value != $this->getAttribute('value')) { return false; } return parent::setValue($value); }
php
{ "resource": "" }
q246626
SimpleTagGroup.isId
validation
public function isId($id) { for ($i = 0, $count = count($this->widgets); $i < $count; $i++) { if ($this->widgets[$i]->isId($id)) { return true; } } return false; }
php
{ "resource": "" }
q246627
SimpleTagGroup.isLabel
validation
public function isLabel($label) { for ($i = 0, $count = count($this->widgets); $i < $count; $i++) { if ($this->widgets[$i]->isLabel($label)) { return true; } } return false; }
php
{ "resource": "" }
q246628
SimpleCheckboxGroup.setValue
validation
public function setValue($values) { $values = $this->makeArray($values); if (! $this->valuesArePossible($values)) { return false; } $widgets = $this->getWidgets(); for ($i = 0, $count = count($widgets); $i < $count; $i++) { $possible = $widgets[$i]->getAttribute('value'); if (in_array($widgets[$i]->getAttribute('value'), $values)) { $widgets[$i]->setValue($possible); } else { $widgets[$i]->setValue(false); } } return true; }
php
{ "resource": "" }
q246629
SimpleCheckboxGroup.valuesArePossible
validation
protected function valuesArePossible($values) { $matches = array(); $widgets = &$this->getWidgets(); for ($i = 0, $count = count($widgets); $i < $count; $i++) { $possible = $widgets[$i]->getAttribute('value'); if (in_array($possible, $values)) { $matches[] = $possible; } } return ($values == $matches); }
php
{ "resource": "" }
q246630
SimpleRadioGroup.setValue
validation
public function setValue($value) { if (! $this->valueIsPossible($value)) { return false; } $index = false; $widgets = $this->getWidgets(); for ($i = 0, $count = count($widgets); $i < $count; $i++) { if (! $widgets[$i]->setValue($value)) { $widgets[$i]->setValue(false); } } return true; }
php
{ "resource": "" }
q246631
SimpleRadioGroup.valueIsPossible
validation
protected function valueIsPossible($value) { $widgets = $this->getWidgets(); for ($i = 0, $count = count($widgets); $i < $count; $i++) { if ($widgets[$i]->getAttribute('value') == $value) { return true; } } return false; }
php
{ "resource": "" }
q246632
SimpleRadioGroup.getValue
validation
public function getValue() { $widgets = $this->getWidgets(); for ($i = 0, $count = count($widgets); $i < $count; $i++) { if ($widgets[$i]->getValue() !== false) { return $widgets[$i]->getValue(); } } return false; }
php
{ "resource": "" }
q246633
XmlReporter.paintPass
validation
public function paintPass($message) { parent::paintPass($message); print $this->getIndent(1); print '<' . $this->namespace . 'pass>'; print $this->toParsedXml($message); print '</' . $this->namespace . "pass>\n"; }
php
{ "resource": "" }
q246634
XmlReporter.paintFail
validation
public function paintFail($message) { parent::paintFail($message); print $this->getIndent(1); print '<' . $this->namespace . 'fail>'; print $this->toParsedXml($message); print '</' . $this->namespace . "fail>\n"; }
php
{ "resource": "" }
q246635
XmlReporter.paintError
validation
public function paintError($message) { parent::paintError($message); print $this->getIndent(1); print '<' . $this->namespace . 'exception>'; print $this->toParsedXml($message); print '</' . $this->namespace . "exception>\n"; }
php
{ "resource": "" }
q246636
XmlReporter.paintException
validation
public function paintException($exception) { parent::paintException($exception); print $this->getIndent(1); print '<' . $this->namespace . 'exception>'; $message = 'Unexpected exception of type [' . get_class($exception) . '] with message [' . $exception->getMessage() . '] in [' . $exception->getFile() . ' line ' . $exception->getLine() . ']'; print $this->toParsedXml($message); print '</' . $this->namespace . "exception>\n"; }
php
{ "resource": "" }
q246637
XmlReporter.paintSkip
validation
public function paintSkip($message) { parent::paintSkip($message); print $this->getIndent(1); print '<' . $this->namespace . 'skip>'; print $this->toParsedXml($message); print '</' . $this->namespace . "skip>\n"; }
php
{ "resource": "" }
q246638
XmlReporter.paintMessage
validation
public function paintMessage($message) { parent::paintMessage($message); print $this->getIndent(1); print '<' . $this->namespace . 'message>'; print $this->toParsedXml($message); print '</' . $this->namespace . "message>\n"; }
php
{ "resource": "" }
q246639
XmlReporter.paintSignal
validation
public function paintSignal($type, $payload) { parent::paintSignal($type, $payload); print $this->getIndent(1); print '<' . $this->namespace . "signal type=\"$type\">"; print '<![CDATA[' . serialize($payload) . ']]>'; print '</' . $this->namespace . "signal>\n"; }
php
{ "resource": "" }
q246640
SimpleCookie.setHost
validation
public function setHost($host) { if ($host = $this->truncateHost($host)) { $this->host = $host; return true; } return false; }
php
{ "resource": "" }
q246641
SimpleCookie.truncateHost
validation
protected function truncateHost($host) { $tlds = SimpleUrl::getAllTopLevelDomains(); if (preg_match('/[a-z\-]+\.(' . $tlds . ')$/i', $host, $matches)) { return $matches[0]; } elseif (preg_match('/[a-z\-]+\.[a-z\-]+\.[a-z\-]+$/i', $host, $matches)) { return $matches[0]; } return false; }
php
{ "resource": "" }
q246642
SimpleCookie.isValidPath
validation
public function isValidPath($path) { return (strncmp($this->fixPath($path), $this->getPath(), strlen($this->getPath())) == 0); }
php
{ "resource": "" }
q246643
SimpleCookie.isExpired
validation
public function isExpired($now) { if (! $this->expiry) { return true; } if (is_string($now)) { $now = strtotime($now); } return ($this->expiry < $now); }
php
{ "resource": "" }
q246644
SimpleCookie.fixPath
validation
protected function fixPath($path) { if (substr($path, 0, 1) != '/') { $path = '/' . $path; } if (substr($path, -1, 1) != '/') { $path .= '/'; } return $path; }
php
{ "resource": "" }
q246645
SimpleCookieJar.restartSession
validation
public function restartSession($date = false) { $surviving_cookies = array(); for ($i = 0; $i < count($this->cookies); $i++) { if (! $this->cookies[$i]->getValue()) { continue; } if (! $this->cookies[$i]->getExpiry()) { continue; } if ($date && $this->cookies[$i]->isExpired($date)) { continue; } $surviving_cookies[] = $this->cookies[$i]; } $this->cookies = $surviving_cookies; }
php
{ "resource": "" }
q246646
SimpleCookieJar.agePrematurely
validation
public function agePrematurely($interval) { for ($i = 0; $i < count($this->cookies); $i++) { $this->cookies[$i]->agePrematurely($interval); } }
php
{ "resource": "" }
q246647
SimpleCookieJar.findFirstMatch
validation
protected function findFirstMatch($cookie) { for ($i = 0; $i < count($this->cookies); $i++) { $is_match = $this->isMatch( $cookie, $this->cookies[$i]->getHost(), $this->cookies[$i]->getPath(), $this->cookies[$i]->getName()); if ($is_match) { return $i; } } return count($this->cookies); }
php
{ "resource": "" }
q246648
SimpleCookieJar.getCookieValue
validation
public function getCookieValue($host, $path, $name) { $longest_path = ''; foreach ($this->cookies as $cookie) { if ($this->isMatch($cookie, $host, $path, $name)) { if (strlen($cookie->getPath()) > strlen($longest_path)) { $value = $cookie->getValue(); $longest_path = $cookie->getPath(); } } } return (isset($value) ? $value : false); }
php
{ "resource": "" }
q246649
SimpleCookieJar.isMatch
validation
protected function isMatch($cookie, $host, $path, $name) { if ($cookie->getName() != $name) { return false; } if ($host && $cookie->getHost() && ! $cookie->isValidHost($host)) { return false; } if (! $cookie->isValidPath($path)) { return false; } return true; }
php
{ "resource": "" }
q246650
SimpleCookieJar.selectAsPairs
validation
public function selectAsPairs($url) { $pairs = array(); foreach ($this->cookies as $cookie) { if ($this->isMatch($cookie, $url->getHost(), $url->getPath(), $cookie->getName())) { $pairs[] = $cookie->getName() . '=' . $cookie->getValue(); } } return $pairs; }
php
{ "resource": "" }
q246651
SimpleFileSocket.close
validation
public function close() { if (!$this->is_open) { return false; } $this->is_open = false; return fclose($this->handle); }
php
{ "resource": "" }
q246652
SimpleSocket.write
validation
public function write($message) { if ($this->isError() || ! $this->isOpen()) { return false; } $count = fwrite($this->handle, $message); if (! $count) { if ($count === false) { $this->setError('Cannot write to socket'); $this->close(); } return false; } fflush($this->handle); $this->sent .= $message; return true; }
php
{ "resource": "" }
q246653
SimpleSocket.read
validation
public function read() { if ($this->isError() || ! $this->isOpen()) { return false; } $raw = @fread($this->handle, $this->block_size); if ($raw === false) { $this->setError('Cannot read from socket'); $this->close(); } return $raw; }
php
{ "resource": "" }
q246654
SimpleRoute.createSocket
validation
protected function createSocket($scheme, $host, $port, $timeout) { if (in_array($scheme, array('file'))) { return new SimpleFileSocket($this->url); } elseif (in_array($scheme, array('https'))) { return new SimpleSecureSocket($host, $port, $timeout); } else { return new SimpleSocket($host, $port, $timeout); } }
php
{ "resource": "" }
q246655
SimpleProxyRoute.getRequestLine
validation
public function getRequestLine($method) { $url = $this->getUrl(); $scheme = $url->getScheme() ? $url->getScheme() : 'http'; $port = $url->getPort() ? ':' . $url->getPort() : ''; return $method . ' ' . $scheme . '://' . $url->getHost() . $port . $url->getPath() . $url->getEncodedRequest() . ' HTTP/1.0'; }
php
{ "resource": "" }
q246656
SimpleHttpRequest.fetch
validation
public function fetch($timeout) { $socket = $this->route->createConnection($this->encoding->getMethod(), $timeout); if (! $socket->isError()) { $this->dispatchRequest($socket, $this->encoding); } return $this->createResponse($socket); }
php
{ "resource": "" }
q246657
SimpleHttpRequest.dispatchRequest
validation
protected function dispatchRequest($socket, $encoding) { foreach ($this->headers as $header_line) { $socket->write($header_line . "\r\n"); } if (count($this->cookies) > 0) { $socket->write('Cookie: ' . implode(';', $this->cookies) . "\r\n"); } $encoding->writeHeadersTo($socket); $socket->write("\r\n"); $encoding->writeTo($socket); }
php
{ "resource": "" }
q246658
SimpleHttpRequest.createResponse
validation
protected function createResponse($socket) { $response = new SimpleHttpResponse( $socket, $this->route->getUrl(), $this->encoding); $socket->close(); return $response; }
php
{ "resource": "" }
q246659
SimpleHttpHeaders.writeCookiesToJar
validation
public function writeCookiesToJar($jar, $url) { foreach ($this->cookies as $cookie) { $jar->setCookie( $cookie->getName(), $cookie->getValue(), $url->getHost(), $cookie->getPath(), $cookie->getExpiry()); } }
php
{ "resource": "" }
q246660
SimpleHttpHeaders.parseHeaderLine
validation
protected function parseHeaderLine($header_line) { if (preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)/i', $header_line, $matches)) { $this->http_version = $matches[1]; $this->response_code = $matches[2]; } if (preg_match('/Content-type:\s*(.*)/i', $header_line, $matches)) { $this->mime_type = trim($matches[1]); } if (preg_match('/Location:\s*(.*)/i', $header_line, $matches)) { $this->location = trim($matches[1]); } if (preg_match('/Set-cookie:(.*)/i', $header_line, $matches)) { $this->cookies[] = $this->parseCookie($matches[1]); } if (preg_match('/WWW-Authenticate:\s+(\S+)\s+realm=\"(.*?)\"/i', $header_line, $matches)) { $this->authentication = $matches[1]; $this->realm = trim($matches[2]); } }
php
{ "resource": "" }
q246661
SimpleHttpHeaders.parseCookie
validation
protected function parseCookie($cookie_line) { $parts = explode(';', $cookie_line); $cookie = array(); preg_match('/\s*(.*?)\s*=(.*)/', array_shift($parts), $cookie); foreach ($parts as $part) { if (preg_match('/\s*(.*?)\s*=(.*)/', $part, $matches)) { $cookie[$matches[1]] = trim($matches[2]); } } return new SimpleCookie( $cookie[1], trim($cookie[2]), isset($cookie['path']) ? $cookie['path'] : '', isset($cookie['expires']) ? $cookie['expires'] : false); }
php
{ "resource": "" }
q246662
SimpleHttpResponse.parse
validation
protected function parse($raw) { if (! $raw) { $this->setError('Nothing fetched'); $this->headers = new SimpleHttpHeaders(''); } elseif ('file' === $this->url->getScheme()) { $this->headers = new SimpleHttpHeaders(''); $this->content = $raw; } elseif (! strstr($raw, "\r\n\r\n")) { $this->setError('Could not split headers from content'); $this->headers = new SimpleHttpHeaders($raw); } else { list($headers, $this->content) = explode("\r\n\r\n", $raw, 2); $this->headers = new SimpleHttpHeaders($headers); } }
php
{ "resource": "" }
q246663
SimpleHttpResponse.readAll
validation
protected function readAll($socket) { $all = ''; while (! $this->isLastPacket($next = $socket->read())) { $all .= $next; } return $all; }
php
{ "resource": "" }
q246664
SimpleExceptionTrappingInvoker.invoke
validation
public function invoke($method) { $trap = SimpleTest::getContext()->get('SimpleExceptionTrap'); $trap->clear(); try { $has_thrown = false; parent::invoke($method); } catch (Exception $exception) { $has_thrown = true; if (! $trap->isExpected($this->getTestCase(), $exception)) { $this->getTestCase()->exception($exception); } $trap->clear(); } if ($message = $trap->getOutstanding()) { $this->getTestCase()->fail($message); } if ($has_thrown) { try { parent::getTestCase()->tearDown(); } catch (Exception $e) { } } }
php
{ "resource": "" }
q246665
SimpleExceptionTrap.expectException
validation
public function expectException($expected = false, $message = '%s') { $this->expected = $this->forceToExpectation($expected); $this->message = $message; }
php
{ "resource": "" }
q246666
SimpleExceptionTrap.isExpected
validation
public function isExpected($test, $exception) { if ($this->expected) { return $test->assert($this->expected, $exception, $this->message); } foreach ($this->ignored as $ignored) { if ($ignored->test($exception)) { return true; } } return false; }
php
{ "resource": "" }
q246667
SimpleExceptionTrap.forceToExpectation
validation
private function forceToExpectation($exception) { if ($exception === false) { return new AnythingExpectation(); } if (! SimpleExpectation::isExpectation($exception)) { return new ExceptionExpectation($exception); } return $exception; }
php
{ "resource": "" }
q246668
SimpleReflection.getInterfaces
validation
public function getInterfaces() { $reflection = new ReflectionClass($this->interface); if ($reflection->isInterface()) { return array($this->interface); } return $this->onlyParents($reflection->getInterfaces()); }
php
{ "resource": "" }
q246669
SimpleReflection.getInterfaceMethods
validation
public function getInterfaceMethods() { $methods = array(); $interfaces = $this->getInterfaces(); foreach ($interfaces as $interface) { $methods = array_merge($methods, get_class_methods($interface)); } return array_unique($methods); }
php
{ "resource": "" }
q246670
SimpleReflection.getParent
validation
public function getParent() { $reflection = new ReflectionClass($this->interface); $parent = $reflection->getParentClass(); if ($parent) { return $parent->getName(); } return false; }
php
{ "resource": "" }
q246671
SimpleReflection.hasFinal
validation
public function hasFinal() { $reflection = new ReflectionClass($this->interface); $methods = $reflection->getMethods(); foreach ($methods as $method) { if ($method->isFinal()) { return true; } } return false; }
php
{ "resource": "" }
q246672
SimpleReflection.onlyParents
validation
protected function onlyParents($interfaces) { $parents = array(); $blacklist = array(); foreach ($interfaces as $interface) { foreach ($interfaces as $possible_parent) { if ($interface->getName() == $possible_parent->getName()) { continue; } if ($interface->isSubClassOf($possible_parent)) { $blacklist[$possible_parent->getName()] = true; } } if (!isset($blacklist[$interface->getName()])) { $parents[] = $interface->getName(); } } return $parents; }
php
{ "resource": "" }
q246673
SimpleReflection.isAbstractMethod
validation
protected function isAbstractMethod($name) { $interface = new ReflectionClass($this->interface); if (! $interface->hasMethod($name)) { return false; } return $interface->getMethod($name)->isAbstract(); }
php
{ "resource": "" }
q246674
SimpleReflection.isAbstractMethodInParents
validation
public function isAbstractMethodInParents($name) { $interface = new ReflectionClass($this->interface); $parent = $interface->getParentClass(); while ($parent) { if (! $parent->hasMethod($name)) { return false; } if ($parent->getMethod($name)->isAbstract()) { return true; } $parent = $parent->getParentClass(); } return false; }
php
{ "resource": "" }
q246675
SimpleReflection.isStaticMethod
validation
protected function isStaticMethod($name) { $interface = new ReflectionClass($this->interface); if (! $interface->hasMethod($name)) { return false; } return $interface->getMethod($name)->isStatic(); }
php
{ "resource": "" }
q246676
SimpleReflection.getSignature
validation
public function getSignature($name) { $interface = new ReflectionClass($this->interface); $method = $interface->getMethod($name); $abstract = ($method->isAbstract() && ! $interface->isInterface() && ! $this->isAbstractMethodInParents($name)) ? 'abstract ' : ''; if ($method->isPublic()) { $visibility = 'public'; } elseif ($method->isProtected()) { $visibility = 'protected'; } else { $visibility = 'private'; } $static = $method->isStatic() ? 'static ' : ''; $reference = $method->returnsReference() ? '&' : ''; $params = $this->getParameterSignatures($method); $returnType = $this->getReturnType($method); return "{$abstract}$visibility {$static}function $reference$name($params){$returnType}"; }
php
{ "resource": "" }
q246677
SimpleReflection.getParameterSignatures
validation
protected function getParameterSignatures($method) { $signatures = []; $parameters = $method->getParameters(); foreach ($parameters as $parameter) { $signature = ''; $signature .= $this->getParameterTypeHint($parameter); if ($parameter->isPassedByReference()) { $signature .= '&'; } // Guard: Variadic methods only supported by PHP 5.6+ $isVariadic = (PHP_VERSION_ID >= 50600) && $parameter->isVariadic(); if ($isVariadic) { $signature .= '...'; } $signature .= '$' . $parameter->getName(); if (!$isVariadic) { if ($parameter->isDefaultValueAvailable()) { $signature .= ' = ' . var_export($parameter->getDefaultValue(), true); } elseif ($parameter->isOptional()) { $signature .= ' = null'; } } $signatures[] = $signature; } return implode(', ', $signatures); }
php
{ "resource": "" }
q246678
ParallelRegex.addPattern
validation
public function addPattern($pattern, $label = true) { $count = count($this->patterns); $this->patterns[$count] = $pattern; $this->labels[$count] = $label; $this->regex = null; }
php
{ "resource": "" }
q246679
ParallelRegex.match
validation
public function match($subject, &$match) { if (count($this->patterns) === 0) { return false; } if (! preg_match($this->getCompoundedRegex(), $subject, $matches)) { $match = ''; return false; } $match = $matches[0]; for ($i = 1; $i < count($matches); $i++) { if ($matches[$i]) { return $this->labels[$i - 1]; } } return true; }
php
{ "resource": "" }
q246680
SimpleLexer.addPattern
validation
public function addPattern($pattern, $mode = 'accept') { if (! isset($this->regexes[$mode])) { $this->regexes[$mode] = new ParallelRegex($this->case); } $this->regexes[$mode]->addPattern($pattern); if (! isset($this->mode_handlers[$mode])) { $this->mode_handlers[$mode] = $mode; } }
php
{ "resource": "" }
q246681
SimpleLexer.addEntryPattern
validation
public function addEntryPattern($pattern, $mode, $new_mode) { if (! isset($this->regexes[$mode])) { $this->regexes[$mode] = new ParallelRegex($this->case); } $this->regexes[$mode]->addPattern($pattern, $new_mode); if (! isset($this->mode_handlers[$new_mode])) { $this->mode_handlers[$new_mode] = $new_mode; } }
php
{ "resource": "" }
q246682
SimpleLexer.parse
validation
public function parse($raw) { if (! isset($this->parser)) { return false; } $length = strlen($raw); while (is_array($parsed = $this->reduce($raw))) { list($raw, $unmatched, $matched, $mode) = $parsed; if (! $this->dispatchTokens($unmatched, $matched, $mode)) { return false; } if ($raw === '') { return true; } if (strlen($raw) == $length) { return false; } $length = strlen($raw); } if (! $parsed) { return false; } return $this->invokeParser($raw, LEXER_UNMATCHED); }
php
{ "resource": "" }
q246683
SimpleLexer.dispatchTokens
validation
protected function dispatchTokens($unmatched, $matched, $mode = false) { if (! $this->invokeParser($unmatched, LEXER_UNMATCHED)) { return false; } if (is_bool($mode)) { return $this->invokeParser($matched, LEXER_MATCHED); } if ($this->isModeEnd($mode)) { if (! $this->invokeParser($matched, LEXER_EXIT)) { return false; } return $this->mode->leave(); } if ($this->isSpecialMode($mode)) { $this->mode->enter($this->decodeSpecial($mode)); if (! $this->invokeParser($matched, LEXER_SPECIAL)) { return false; } return $this->mode->leave(); } $this->mode->enter($mode); return $this->invokeParser($matched, LEXER_ENTER); }
php
{ "resource": "" }
q246684
SimpleLexer.invokeParser
validation
protected function invokeParser($content, $is_match) { if (($content === '') || ($content === false)) { return true; } $handler = $this->mode_handlers[$this->mode->getCurrent()]; return $this->parser->$handler($content, $is_match); }
php
{ "resource": "" }
q246685
SimpleLexer.reduce
validation
protected function reduce($raw) { if ($action = $this->regexes[$this->mode->getCurrent()]->match($raw, $match)) { $unparsed_character_count = strpos($raw, $match); $unparsed = substr($raw, 0, $unparsed_character_count); $raw = substr($raw, $unparsed_character_count + strlen($match)); return array($raw, $unparsed, $match, $action); } return true; }
php
{ "resource": "" }
q246686
SimpleHtmlLexer.addSkipping
validation
protected function addSkipping() { $this->mapHandler('css', 'ignore'); $this->addEntryPattern('<style', 'text', 'css'); $this->addExitPattern('</style>', 'css'); $this->mapHandler('js', 'ignore'); $this->addEntryPattern('<script', 'text', 'js'); $this->addExitPattern('</script>', 'js'); $this->mapHandler('comment', 'ignore'); $this->addEntryPattern('<!--', 'text', 'comment'); $this->addExitPattern('-->', 'comment'); }
php
{ "resource": "" }
q246687
SimpleHtmlLexer.addInTagTokens
validation
protected function addInTagTokens() { $this->mapHandler('tag', 'acceptStartToken'); $this->addSpecialPattern('\s+', 'tag', 'ignore'); $this->addAttributeTokens(); $this->addExitPattern('/>', 'tag'); $this->addExitPattern('>', 'tag'); }
php
{ "resource": "" }
q246688
SimpleHtmlLexer.addAttributeTokens
validation
protected function addAttributeTokens() { $this->mapHandler('dq_attribute', 'acceptAttributeToken'); $this->addEntryPattern('=\s*"', 'tag', 'dq_attribute'); $this->addPattern('\\\\"', 'dq_attribute'); $this->addExitPattern('"', 'dq_attribute'); $this->mapHandler('sq_attribute', 'acceptAttributeToken'); $this->addEntryPattern("=\s*'", 'tag', 'sq_attribute'); $this->addPattern("\\\\'", 'sq_attribute'); $this->addExitPattern("'", 'sq_attribute'); $this->mapHandler('uq_attribute', 'acceptAttributeToken'); $this->addSpecialPattern('=\s*[^>\s]*', 'tag', 'uq_attribute'); }
php
{ "resource": "" }
q246689
SimpleHtmlSaxParser.acceptStartToken
validation
public function acceptStartToken($token, $event) { if ($event == LEXER_ENTER) { $this->tag = strtolower(substr($token, 1)); return true; } if ($event == LEXER_EXIT) { $success = $this->listener->startElement( $this->tag, $this->attributes); $this->tag = ''; $this->attributes = array(); return $success; } if ($token !== '=') { $this->current_attribute = strtolower(html_entity_decode($token, ENT_QUOTES)); $this->attributes[$this->current_attribute] = ''; } return true; }
php
{ "resource": "" }
q246690
SimpleHtmlSaxParser.acceptEndToken
validation
public function acceptEndToken($token, $event) { if (! preg_match('/<\/(.*)>/', $token, $matches)) { return false; } return $this->listener->endElement(strtolower($matches[1])); }
php
{ "resource": "" }
q246691
SimpleHtmlSaxParser.acceptAttributeToken
validation
public function acceptAttributeToken($token, $event) { if ($this->current_attribute) { if ($event == LEXER_UNMATCHED) { $this->attributes[$this->current_attribute] .= html_entity_decode($token, ENT_QUOTES); } if ($event == LEXER_SPECIAL) { $this->attributes[$this->current_attribute] .= preg_replace('/^=\s*/', '', html_entity_decode($token, ENT_QUOTES)); } } return true; }
php
{ "resource": "" }
q246692
SimplePhpPageBuilder.parse
validation
public function parse($response) { $this->tags = array(); $this->page = $this->createPage($response); $parser = $this->createParser($this); $parser->parse($response->getContent()); $this->acceptPageEnd(); $page = $this->page; $this->free(); return $page; }
php
{ "resource": "" }
q246693
SimplePhpPageBuilder.startElement
validation
public function startElement($name, $attributes) { $factory = new SimpleTagBuilder(); $tag = $factory->createTag($name, $attributes); if (! $tag) { return true; } if ($tag->getTagName() === 'label') { $this->acceptLabelStart($tag); $this->openTag($tag); return true; } if ($tag->getTagName() === 'form') { $this->acceptFormStart($tag); return true; } if ($tag->getTagName() === 'frameset') { $this->acceptFramesetStart($tag); return true; } if ($tag->getTagName() === 'frame') { $this->acceptFrame($tag); return true; } if ($tag->isPrivateContent() && ! isset($this->private_content_tag)) { $this->private_content_tag = $tag; } if ($tag->expectEndTag()) { $this->openTag($tag); return true; } $this->acceptTag($tag); return true; }
php
{ "resource": "" }
q246694
SimplePhpPageBuilder.endElement
validation
public function endElement($name) { if ($name === 'label') { $this->acceptLabelEnd(); return true; } if ($name === 'form') { $this->acceptFormEnd(); return true; } if ($name === 'frameset') { $this->acceptFramesetEnd(); return true; } if ($this->hasNamedTagOnOpenTagStack($name)) { $tag = array_pop($this->tags[$name]); if ($tag->isPrivateContent() && $this->private_content_tag->getTagName() == $name) { unset($this->private_content_tag); } $this->addContentTagToOpenTags($tag); $this->acceptTag($tag); return true; } return true; }
php
{ "resource": "" }
q246695
SimplePhpPageBuilder.hasNamedTagOnOpenTagStack
validation
protected function hasNamedTagOnOpenTagStack($name) { return isset($this->tags[$name]) && (count($this->tags[$name]) > 0); }
php
{ "resource": "" }
q246696
SimplePhpPageBuilder.addContent
validation
public function addContent($text) { if (isset($this->private_content_tag)) { $this->private_content_tag->addContent($text); } else { $this->addContentToAllOpenTags($text); } return true; }
php
{ "resource": "" }
q246697
SimplePhpPageBuilder.addContentToAllOpenTags
validation
protected function addContentToAllOpenTags($text) { foreach (array_keys($this->tags) as $name) { for ($i = 0, $count = count($this->tags[$name]); $i < $count; $i++) { $this->tags[$name][$i]->addContent($text); } } }
php
{ "resource": "" }
q246698
SimplePhpPageBuilder.addContentTagToOpenTags
validation
protected function addContentTagToOpenTags(&$tag) { if ($tag->getTagName() != 'option') { return; } foreach (array_keys($this->tags) as $name) { for ($i = 0, $count = count($this->tags[$name]); $i < $count; $i++) { $this->tags[$name][$i]->addTag($tag); } } }
php
{ "resource": "" }
q246699
SimplePhpPageBuilder.openTag
validation
protected function openTag($tag) { $name = $tag->getTagName(); if (! in_array($name, array_keys($this->tags))) { $this->tags[$name] = array(); } $this->tags[$name][] = $tag; }
php
{ "resource": "" }