_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q255500
RetryMiddlewareFactory.generalRetryDecider
test
protected static function generalRetryDecider($statusCode, $isSecondary) { $retry = false; if ($statusCode == 408) { $retry = true; } elseif ($statusCode >= 500) { if ($statusCode != 501 && $statusCode != 505) { $retry = true; } } elseif ($isSecondary && $statusCode == 404) { $retry = true; } return $retry; }
php
{ "resource": "" }
q255501
RestProxy.addOptionalQueryParam
test
protected function addOptionalQueryParam(array &$queryParameters, $key, $value) { Validate::isArray($queryParameters, 'queryParameters'); Validate::canCastAsString($key, 'key'); Validate::canCastAsString($value, 'value'); if (!is_null($value) && Resources::EMPTY_STRING !== $value) { $queryParameters[$key] = $value; } }
php
{ "resource": "" }
q255502
RestProxy.addOptionalHeader
test
protected function addOptionalHeader(array &$headers, $key, $value) { Validate::isArray($headers, 'headers'); Validate::canCastAsString($key, 'key'); Validate::canCastAsString($value, 'value'); if (!is_null($value) && Resources::EMPTY_STRING !== $value) { $headers[$key] = $value; } }
php
{ "resource": "" }
q255503
GetFileResult.create
test
public static function create( array $headers, StreamInterface $body, array $metadata ) { $result = new GetFileResult(); $result->setContentStream($body->detach()); $result->setProperties(FileProperties::createFromHttpHeaders($headers)); $result->setMetadata(is_null($metadata) ? array() : $metadata); return $result; }
php
{ "resource": "" }
q255504
MessageSerializer.serializeHeaders
test
private static function serializeHeaders(array $headers) { $resultString = "Headers:\n"; foreach ($headers as $key => $value) { $resultString .= sprintf("%s: %s\n", $key, $value[0]); } return $resultString; }
php
{ "resource": "" }
q255505
MessageSerializer.serializeRequestException
test
private static function serializeRequestException(RequestException $e) { $resultString = sprintf("Reason:\n%s\n", $e); if ($e->hasResponse()) { $resultString .= self::serializeResponse($e->getResponse()); } return $resultString; }
php
{ "resource": "" }
q255506
CreateMessageResult.create
test
public static function create($parsedResponse) { $result = new CreateMessageResult(); if (!empty($parsedResponse) && !empty($parsedResponse[Resources::QP_QUEUE_MESSAGE]) ) { $result->setQueueMessage( QueueMessage::createFromCreateMessage( $parsedResponse[Resources::QP_QUEUE_MESSAGE] ) ); } return $result; }
php
{ "resource": "" }
q255507
InsertEntityResult.create
test
public static function create($body, $headers, $odataSerializer) { $result = new InsertEntityResult(); $entity = $odataSerializer->parseEntity($body); $entity->setETag(Utilities::tryGetValue($headers, Resources::ETAG)); $result->setEntity($entity); return $result; }
php
{ "resource": "" }
q255508
QueryEntitiesResult.create
test
public static function create(array $headers, array $entities) { $result = new QueryEntitiesResult(); $headers = array_change_key_case($headers); $nextPK = Utilities::tryGetValue( $headers, Resources::X_MS_CONTINUATION_NEXTPARTITIONKEY ); $nextRK = Utilities::tryGetValue( $headers, Resources::X_MS_CONTINUATION_NEXTROWKEY ); if ($nextRK != null && $nextPK != null) { $result->setContinuationToken( new TableContinuationToken( '', $nextPK, $nextRK, Utilities::getLocationFromHeaders($headers) ) ); } $result->setEntities($entities); return $result; }
php
{ "resource": "" }
q255509
HttpFormatter.formatHeaders
test
public static function formatHeaders(array $headers) { $result = array(); foreach ($headers as $key => $value) { if (is_array($value) && count($value) == 1) { $result[strtolower($key)] = $value[0]; } else { $result[strtolower($key)] = $value; } } return $result; }
php
{ "resource": "" }
q255510
File.create
test
public static function create(array $parsed) { $result = new File(); $name = Utilities::tryGetValue($parsed, Resources::QP_NAME); $result->setName($name); $properties = Utilities::tryGetValue($parsed, Resources::QP_PROPERTIES); $length = \intval(Utilities::tryGetValue($properties, Resources::QP_CONTENT_LENGTH)); $result->setLength($length); return $result; }
php
{ "resource": "" }
q255511
MiddlewareStack.apply
test
public function apply(callable $handler) { $result = $handler; foreach ($this->middlewares as $middleware) { $result = $middleware($result); } return $result; }
php
{ "resource": "" }
q255512
OverridesFractal.getAvailableIncludes
test
public function getAvailableIncludes() { if ($this->relations == ['*']) { return $this->resolveScopedIncludes($this->getCurrentScope()); } return array_keys($this->normalizeRelations($this->relations)); }
php
{ "resource": "" }
q255513
OverridesFractal.callIncludeMethod
test
protected function callIncludeMethod(Scope $scope, $identifier, $data) { $parameters = iterator_to_array($scope->getManager()->getIncludeParams($scope->getIdentifier($identifier))); return $this->includeResource($identifier, $data, $parameters); }
php
{ "resource": "" }
q255514
OverridesFractal.resolveScopedIncludes
test
protected function resolveScopedIncludes(Scope $scope): array { $level = count($scope->getParentScopes()); $includes = $scope->getManager()->getRequestedIncludes(); return collect($includes)->map(function ($include) { return explode('.', $include); })->filter(function ($include) use ($level) { return count($include) > $level; })->pluck($level)->unique()->all(); }
php
{ "resource": "" }
q255515
ErrorResponseBuilder.error
test
public function error($errorCode = null, string $message = null) { $this->errorCode = $errorCode; $this->message = $message; return $this; }
php
{ "resource": "" }
q255516
ErrorResponseBuilder.data
test
public function data(array $data = null) { $this->data = array_merge((array) $this->data, (array) $data); return $this; }
php
{ "resource": "" }
q255517
ErrorResponseBuilder.serializer
test
public function serializer($serializer) { if (is_string($serializer)) { $serializer = new $serializer; } if (! $serializer instanceof ErrorSerializer) { throw new InvalidErrorSerializerException; } $this->serializer = $serializer; return $this; }
php
{ "resource": "" }
q255518
ErrorResponseBuilder.getOutput
test
protected function getOutput(): array { return $this->errorFactory->make($this->serializer, $this->errorCode, $this->message, $this->data); }
php
{ "resource": "" }
q255519
TransformBuilder.resource
test
public function resource($data = null, $transformer = null, string $resourceKey = null) { $this->resource = $this->resourceFactory->make($data, $transformer, $resourceKey); if ($data instanceof CursorPaginator) { $this->cursor($this->paginatorFactory->makeCursor($data)); } elseif ($data instanceof LengthAwarePaginator) { $this->paginator($this->paginatorFactory->make($data)); } return $this; }
php
{ "resource": "" }
q255520
TransformBuilder.cursor
test
public function cursor(Cursor $cursor) { if ($this->resource instanceof CollectionResource) { $this->resource->setCursor($cursor); } return $this; }
php
{ "resource": "" }
q255521
TransformBuilder.paginator
test
public function paginator(IlluminatePaginatorAdapter $paginator) { if ($this->resource instanceof CollectionResource) { $this->resource->setPaginator($paginator); } return $this; }
php
{ "resource": "" }
q255522
TransformBuilder.with
test
public function with($relations) { $relations = is_array($relations) ? $relations : func_get_args(); foreach ($relations as $relation => $constraint) { if (is_numeric($relation)) { $relation = $constraint; $constraint = null; } $this->with = array_merge($this->with, [$relation => $constraint]); } return $this; }
php
{ "resource": "" }
q255523
TransformBuilder.without
test
public function without($relations) { $this->without = array_merge($this->without, is_array($relations) ? $relations : func_get_args()); return $this; }
php
{ "resource": "" }
q255524
TransformBuilder.only
test
public function only($fields) { $this->only = array_merge($this->only, is_array($fields) ? $fields : func_get_args()); return $this; }
php
{ "resource": "" }
q255525
TransformBuilder.serializer
test
public function serializer($serializer) { if (is_string($serializer)) { $serializer = new $serializer; } if (! $serializer instanceof SerializerAbstract) { throw new InvalidSuccessSerializerException; } $this->serializer = $serializer; return $this; }
php
{ "resource": "" }
q255526
TransformBuilder.transform
test
public function transform() { $this->prepareRelations($this->resource->getData(), $this->resource->getTransformer()); return $this->transformFactory->make($this->resource ?: new NullResource, $this->serializer, [ 'includes' => $this->with, 'excludes' => $this->without, 'fieldsets' => $this->only, ]); }
php
{ "resource": "" }
q255527
TransformBuilder.prepareRelations
test
protected function prepareRelations($data, $transformer) { if ($transformer instanceof Transformer) { $relations = $transformer->relations($this->with); $defaultRelations = $this->removeExcludedRelations($transformer->defaultRelations($this->with)); $this->with = array_merge($relations, $defaultRelations); } if ($data instanceof Model || $data instanceof Collection) { $this->eagerLoadRelations($data, $this->with, $transformer); } $this->with = array_keys($this->with); }
php
{ "resource": "" }
q255528
TransformBuilder.eagerLoadRelations
test
protected function eagerLoadRelations($data, array $requested, $transformer) { $relations = collect(array_keys($requested))->reduce(function ($eagerLoads, $relation) use ($requested, $transformer) { $identifier = camel_case($this->stripParametersFromRelation($relation)); if (method_exists($transformer, 'include' . ucfirst($identifier))) { return $eagerLoads; } return array_merge($eagerLoads, [$identifier => $requested[$relation] ?: function () { }]); }, []); $data->load($relations); }
php
{ "resource": "" }
q255529
SuccessSerializer.paginator
test
public function paginator(PaginatorInterface $paginator) { $pagination = parent::paginator($paginator)['pagination']; return [ 'pagination' => [ 'count' => $pagination['count'], 'total' => $pagination['total'], 'perPage' => $pagination['per_page'], 'currentPage' => $pagination['current_page'], 'totalPages' => $pagination['total_pages'], 'links' => $pagination['links'], ], ]; }
php
{ "resource": "" }
q255530
SuccessSerializer.cursor
test
public function cursor(CursorInterface $cursor) { return [ 'cursor' => [ 'current' => $cursor->getCurrent(), 'previous' => $cursor->getPrev(), 'next' => $cursor->getNext(), 'count' => (int) $cursor->getCount(), ], ]; }
php
{ "resource": "" }
q255531
SuccessSerializer.mergeIncludes
test
public function mergeIncludes($transformedData, $includedData) { foreach (array_keys($includedData) as $key) { $includedData[$key] = $includedData[$key]['data']; } return array_merge($transformedData, $includedData); }
php
{ "resource": "" }
q255532
ResourceKeyResolver.bind
test
public function bind($transformable, string $resourceKey) { $this->bindings = array_merge($this->bindings, is_array($transformable) ? $transformable : [ $transformable => $resourceKey, ]); }
php
{ "resource": "" }
q255533
ResourceKeyResolver.resolve
test
public function resolve($data) { $transformable = $this->resolveTransformableItem($data); if (is_object($transformable) && key_exists(get_class($transformable), $this->bindings)) { return $this->bindings[get_class($transformable)]; } if ($transformable instanceof Model) { return $this->resolveFromModel($transformable); } return 'data'; }
php
{ "resource": "" }
q255534
ResourceKeyResolver.resolveTransformableItem
test
protected function resolveTransformableItem($data) { if (is_array($data) || $data instanceof Traversable) { foreach ($data as $item) { return $item; } } return $data; }
php
{ "resource": "" }
q255535
Transformer.resolveTransformer
test
protected function resolveTransformer(string $transformer) { $transformerResolver = $this->resolveContainer()->make(TransformerResolver::class); return $transformerResolver->resolve($transformer); }
php
{ "resource": "" }
q255536
Handler.render
test
public function render($request, Exception $exception) { if ($request->wantsJson()) { $this->convertDefaultException($exception); if ($exception instanceof HttpException) { return $this->renderResponse($exception); } } return parent::render($request, $exception); }
php
{ "resource": "" }
q255537
ErrorFactory.make
test
public function make(ErrorSerializer $serializer, $errorCode = null, string $message = null, array $data = null): array { if (isset($errorCode) && ! isset($message)) { $message = $this->messageResolver->resolve($errorCode); } return $serializer->format($errorCode, $message, $data); }
php
{ "resource": "" }
q255538
FractalTransformFactory.make
test
public function make(ResourceInterface $resource, SerializerAbstract $serializer, array $options = []) { $options = $this->parseOptions($options, $resource); return $this->manager->setSerializer($serializer) ->parseIncludes($options['includes']) ->parseExcludes($options['excludes']) ->parseFieldsets($options['fieldsets']) ->createData($resource) ->toArray(); }
php
{ "resource": "" }
q255539
FractalTransformFactory.parseOptions
test
protected function parseOptions(array $options, ResourceInterface $resource): array { $options = array_merge([ 'includes' => [], 'excludes' => [], 'fieldsets' => [], ], $options); if (! empty($options['fieldsets'])) { if (is_null($resourceKey = $resource->getResourceKey())) { throw new LogicException('Filtering fields using sparse fieldsets require resource key to be set.'); } $options['fieldsets'] = $this->parseFieldsets($options['fieldsets'], $resourceKey, $options['includes']); } return $options; }
php
{ "resource": "" }
q255540
FractalTransformFactory.parseFieldsets
test
protected function parseFieldsets(array $fieldsets, string $resourceKey, array $includes): array { $includes = array_map(function ($include) use ($resourceKey) { return "$resourceKey.$include"; }, $includes); foreach ($fieldsets as $key => $fields) { if (is_numeric($key)) { unset($fieldsets[$key]); $key = $resourceKey; } $fields = $this->parseFieldset($key, (array) $fields, $includes); $fieldsets[$key] = array_unique(array_merge(key_exists($key, $fieldsets) ? (array) $fieldsets[$key] : [], $fields)); } return array_map(function ($fields) { return implode(',', $fields); }, $fieldsets); }
php
{ "resource": "" }
q255541
FractalTransformFactory.parseFieldset
test
protected function parseFieldset(string $key, array $fields, array $includes): array { $childIncludes = array_reduce($includes, function ($segments, $include) use ($key) { return array_merge($segments, $this->resolveChildIncludes($key, $include)); }, []); return array_merge($fields, array_unique($childIncludes)); }
php
{ "resource": "" }
q255542
FractalTransformFactory.resolveChildIncludes
test
protected function resolveChildIncludes($key, string $include): array { if (count($segments = explode('.', $include)) <= 1) { return []; } $relation = $key === array_shift($segments) ? [$segments[0]] : []; return array_merge($relation, $this->resolveChildIncludes($key, implode('.', $segments))); }
php
{ "resource": "" }
q255543
ErrorMessageResolver.register
test
public function register($errorCode, string $message) { $this->messages = array_merge($this->messages, is_array($errorCode) ? $errorCode : [ $errorCode => $message, ]); }
php
{ "resource": "" }
q255544
ErrorMessageResolver.resolve
test
public function resolve($errorCode) { if (key_exists($errorCode, $this->messages)) { return $this->messages[$errorCode]; } if ($this->translator->has($errorCode = "errors.$errorCode")) { return $this->translator->trans($errorCode); } return null; }
php
{ "resource": "" }
q255545
ConvertToSnakeCase.cleanArray
test
protected function cleanArray(array $data) { $parameters = []; foreach ($data as $key => $value) { $parameters[in_array($key, $this->except) ? $key : snake_case($key)] = $value; } return $parameters; }
php
{ "resource": "" }
q255546
TransformerResolver.bind
test
public function bind($transformable, $transformer = null) { $this->bindings = array_merge($this->bindings, is_array($transformable) ? $transformable : [ $transformable => $transformer, ]); }
php
{ "resource": "" }
q255547
TransformerResolver.resolveFromData
test
public function resolveFromData($data) { $transformer = $this->resolveTransformer($this->resolveTransformableItem($data)); return $this->resolve($transformer); }
php
{ "resource": "" }
q255548
TransformerResolver.resolveTransformer
test
protected function resolveTransformer($transformable) { if (is_object($transformable) && key_exists(get_class($transformable), $this->bindings)) { return $this->bindings[get_class($transformable)]; } if ($transformable instanceof Transformable) { return $transformable->transformer(); } return $this->resolve($this->fallback); }
php
{ "resource": "" }
q255549
ResponderServiceProvider.registerLaravelBindings
test
protected function registerLaravelBindings() { $this->app->singleton(ResponseFactoryContract::class, function ($app) { return $this->decorateResponseFactory($app->make(LaravelResponseFactory::class)); }); }
php
{ "resource": "" }
q255550
ResponderServiceProvider.registerLumenBindings
test
protected function registerLumenBindings() { $this->app->singleton(ResponseFactoryContract::class, function ($app) { return $this->decorateResponseFactory($app->make(LumenResponseFactory::class)); }); $this->app->bind(Translator::class, function ($app) { return $app['translator']; }); }
php
{ "resource": "" }
q255551
ResponderServiceProvider.decorateResponseFactory
test
protected function decorateResponseFactory(ResponseFactoryContract $factory): ResponseFactory { foreach ($this->app->config['responder.decorators'] as $decorator) { $factory = new $decorator($factory); }; return $factory; }
php
{ "resource": "" }
q255552
ResponderServiceProvider.registerSerializerBindings
test
protected function registerSerializerBindings() { $this->app->bind(ErrorSerializerContract::class, function ($app) { return $app->make($app->config['responder.serializers.error']); }); $this->app->bind(SerializerAbstract::class, function ($app) { return $app->make($app->config['responder.serializers.success']); }); }
php
{ "resource": "" }
q255553
ResponderServiceProvider.registerErrorBindings
test
protected function registerErrorBindings() { $this->app->singleton(ErrorMessageResolverContract::class, function ($app) { return $app->make(ErrorMessageResolver::class); }); $this->app->singleton(ErrorFactoryContract::class, function ($app) { return $app->make(ErrorFactory::class); }); $this->app->bind(ErrorResponseBuilder::class, function ($app) { return (new ErrorResponseBuilder($app->make(ResponseFactoryContract::class), $app->make(ErrorFactoryContract::class)))->serializer($app->make(ErrorSerializerContract::class)); }); }
php
{ "resource": "" }
q255554
ResponderServiceProvider.registerFractalBindings
test
protected function registerFractalBindings() { $this->app->bind(Manager::class, function ($app) { return (new Manager)->setRecursionLimit($app->config['responder.recursion_limit']); }); }
php
{ "resource": "" }
q255555
ResponderServiceProvider.registerTransformerBindings
test
protected function registerTransformerBindings() { $this->app->singleton(TransformerResolverContract::class, function ($app) { return new TransformerResolver($app, $app->config['responder.fallback_transformer']); }); BaseTransformer::containerResolver(function () { return $this->app->make(Container::class); }); }
php
{ "resource": "" }
q255556
ResponderServiceProvider.registerTransformationBindings
test
protected function registerTransformationBindings() { $this->app->bind(TransformFactoryContract::class, function ($app) { return $app->make(FractalTransformFactory::class); }); $this->app->bind(TransformBuilder::class, function ($app) { $request = $this->app->make(Request::class); $relations = $request->input($this->app->config['responder.load_relations_parameter'], []); $fieldsets = $request->input($app->config['responder.filter_fields_parameter'], []); return (new TransformBuilder($app->make(ResourceFactoryContract::class), $app->make(TransformFactoryContract::class), $app->make(PaginatorFactoryContract::class)))->serializer($app->make(SerializerAbstract::class)) ->with(is_string($relations) ? explode(',', $relations) : $relations) ->only($fieldsets); }); }
php
{ "resource": "" }
q255557
ResponderServiceProvider.bootLaravelApplication
test
protected function bootLaravelApplication() { if ($this->app->runningInConsole()) { $this->publishes([ __DIR__ . '/../config/responder.php' => config_path('responder.php'), ], 'config'); $this->publishes([ __DIR__ . '/../resources/lang/en/errors.php' => base_path('resources/lang/en/errors.php'), ], 'lang'); } }
php
{ "resource": "" }
q255558
CursorPaginator.set
test
public function set($data): CursorPaginator { $this->items = $data instanceof Collection ? $data : collect($data); return $this; }
php
{ "resource": "" }
q255559
ErrorSerializer.format
test
public function format($errorCode = null, string $message = null, array $data = null): array { $response = [ 'error' => [ 'code' => $errorCode, 'message' => $message, ], ]; if (is_array($data)) { $response['error'] = array_merge($response['error'], $data); } return $response; }
php
{ "resource": "" }
q255560
HasRelationships.relations
test
public function relations(array $requested = []): array { $requested = $this->normalizeRelations($requested); $relations = $this->applyQueryConstraints($this->extractRelations($requested)); $nestedRelations = $this->nestedRelations($requested, $relations, 'relations'); return array_merge($relations, $nestedRelations); }
php
{ "resource": "" }
q255561
HasRelationships.defaultRelations
test
public function defaultRelations(array $requested = []): array { $requested = $this->normalizeRelations($requested); $relations = $this->applyQueryConstraints($this->normalizeRelations($this->load)); $nestedRelations = $this->nestedRelations($relations, array_merge($relations, $requested), 'defaultRelations'); return array_merge($relations, $nestedRelations); }
php
{ "resource": "" }
q255562
HasRelationships.extractRelations
test
protected function extractRelations(array $relations): array { $available = $this->availableRelations(); return array_filter($this->mapRelations($relations, function ($relation, $constraint) { $identifier = explode('.', $relation)[0]; $constraint = $identifier === $relation ? $constraint : null; return [$identifier => $constraint ?: $this->resolveQueryConstraint($identifier)]; }), function ($relation) use ($available) { return array_has($available, explode(':', $relation)[0]); }, ARRAY_FILTER_USE_KEY); }
php
{ "resource": "" }
q255563
HasRelationships.extractChildRelations
test
protected function extractChildRelations(array $relations, string $identifier): array { return array_reduce(array_keys($relations), function ($nested, $relation) use ($relations, $identifier) { if (! starts_with($relation, "$identifier.")) { return $nested; } $nestedIdentifier = explode('.', $relation); array_shift($nestedIdentifier); return array_merge($nested, [implode('.', $nestedIdentifier) => $relations[$relation]]); }, []); }
php
{ "resource": "" }
q255564
HasRelationships.wrapChildRelations
test
protected function wrapChildRelations(array $nestedRelations, string $relation): array { return $this->mapRelations($nestedRelations, function ($nestedRelation, $constraint) use ($relation) { return ["$relation.$nestedRelation" => $constraint]; }); }
php
{ "resource": "" }
q255565
HasRelationships.applyQueryConstraints
test
protected function applyQueryConstraints(array $relations): array { return $this->mapRelations($relations, function ($relation, $constraint) { return [$relation => is_callable($constraint) ? $constraint : $this->resolveQueryConstraint($relation)]; }); }
php
{ "resource": "" }
q255566
HasRelationships.resolveQueryConstraint
test
protected function resolveQueryConstraint(string $identifier) { if (! method_exists($this, $method = 'load' . ucfirst(camel_case($identifier)))) { return null; } return function ($query) use ($method) { return $this->$method($query); }; }
php
{ "resource": "" }
q255567
HasRelationships.resolveRelation
test
protected function resolveRelation(Model $model, string $identifier) { $identifier = camel_case($identifier); $relation = $model->$identifier; if (method_exists($this, $method = 'filter' . ucfirst($identifier))) { return $this->$method($relation); } return $relation; }
php
{ "resource": "" }
q255568
HasRelationships.mappedTransformers
test
protected function mappedTransformers(array $relations): array { $transformers = collect($this->availableRelations())->filter(function ($transformer) { return ! is_null($transformer); })->map(function ($transformer) { return $this->resolveTransformer($transformer); })->all(); return array_intersect_key($transformers, $relations); }
php
{ "resource": "" }
q255569
MakesResources.resource
test
protected function resource($data = null, $transformer = null, string $resourceKey = null): ResourceInterface { if ($data instanceof ResourceInterface) { return $data; } $resourceFactory = $this->resolveContainer()->make(ResourceFactory::class); return $resourceFactory->make($data, $transformer, $resourceKey); }
php
{ "resource": "" }
q255570
MakesResources.includeResource
test
protected function includeResource(string $identifier, $data, array $parameters): ResourceInterface { $transformer = $this->mappedTransformerClass($identifier); if (method_exists($this, $method = 'include' . ucfirst(camel_case($identifier)))) { $resource = $this->resource($this->$method($data, collect($parameters)), $transformer, $identifier); } elseif ($data instanceof Model) { $resource = $this->includeResourceFromModel($data, $identifier, $transformer); } else { throw new LogicException('Relation [' . $identifier . '] not found in [' . get_class($this) . '].'); } return $resource; }
php
{ "resource": "" }
q255571
MakesResources.includeResourceFromModel
test
protected function includeResourceFromModel(Model $model, string $identifier, $transformer = null): ResourceInterface { $data = $this->resolveRelation($model, $identifier); if (! $this->shouldCacheResource($data)) { return $this->resource($data, $transformer, $identifier); } elseif (key_exists($identifier, $this->resources)) { return $this->resources[$identifier]->setData($data); } return $this->resources[$identifier] = $this->resource($data, $transformer, $identifier); }
php
{ "resource": "" }
q255572
MakesResources.shouldCacheResource
test
protected function shouldCacheResource($data): bool { return is_array($data) || $data instanceof Countable ? count($data) > 0 : is_null($data); }
php
{ "resource": "" }
q255573
ResourceFactory.make
test
public function make($data = null, $transformer = null, string $resourceKey = null): ResourceInterface { if ($data instanceof ResourceInterface) { return $this->makeFromResource($data, $transformer, $resourceKey); } elseif (is_null($data = $this->normalizer->normalize($data))) { return $this->instatiateResource($data, null, $resourceKey); } $transformer = $this->resolveTransformer($data, $transformer); $resourceKey = $this->resolveResourceKey($data, $resourceKey); return $this->instatiateResource($data, $transformer, $resourceKey); }
php
{ "resource": "" }
q255574
ResourceFactory.makeFromResource
test
public function makeFromResource(ResourceInterface $resource, $transformer = null, string $resourceKey = null): ResourceInterface { $transformer = $this->resolveTransformer($resource->getData(), $transformer ?: $resource->getTransformer()); $resourceKey = $this->resolveResourceKey($resource->getData(), $resourceKey ?: $resource->getResourceKey()); return $resource->setTransformer($transformer)->setResourceKey($resourceKey); }
php
{ "resource": "" }
q255575
ResourceFactory.instatiateResource
test
protected function instatiateResource($data, $transformer = null, string $resourceKey = null): ResourceInterface { if (is_null($data)) { return new NullResource(null, null, $resourceKey); } elseif ($this->shouldCreateCollection($data)) { return new CollectionResource($data, $transformer, $resourceKey); } elseif (is_scalar($data)) { return new Primitive($data, $transformer, $resourceKey); } return new ItemResource($data, $transformer, $resourceKey); }
php
{ "resource": "" }
q255576
ResourceFactory.shouldCreateCollection
test
protected function shouldCreateCollection($data): bool { if (is_array($data)) { return ! Arr::isAssoc($data) && ! is_scalar(Arr::first($data)); } return $data instanceof Traversable; }
php
{ "resource": "" }
q255577
ResourceFactory.resolveResourceKey
test
protected function resolveResourceKey($data, string $resourceKey = null) { return isset($resourceKey) ? $resourceKey : $this->resourceKeyResolver->resolve($data); }
php
{ "resource": "" }
q255578
ResponseBuilder.decorator
test
public function decorator($decorator) { $decorators = is_array($decorator) ? $decorator : func_get_args(); foreach ($decorators as $decorator) { $this->responseFactory = new $decorator($this->responseFactory); }; return $this; }
php
{ "resource": "" }
q255579
ResponseBuilder.respond
test
public function respond(int $status = null, array $headers = []): JsonResponse { if (! is_null($status)) { $this->setStatusCode($status); } return $this->responseFactory->make($this->getOutput(), $this->status, $headers); }
php
{ "resource": "" }
q255580
DataNormalizer.normalize
test
public function normalize($data = null) { if ($this->isInstanceOf($data, [Builder::class, EloquentBuilder::class, CursorPaginator::class])) { return $data->get(); } elseif ($data instanceof Paginator) { return $data->getCollection(); } elseif ($data instanceof Relation) { return $this->normalizeRelation($data); } return $data; }
php
{ "resource": "" }
q255581
DataNormalizer.normalizeRelation
test
protected function normalizeRelation(Relation $relation) { if ($this->isInstanceOf($relation, [BelongsTo::class, HasOne::class, MorphOne::class, MorphTo::class])) { return $relation->first(); } return $relation->get(); }
php
{ "resource": "" }
q255582
SuccessResponseBuilder.transform
test
public function transform($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder { $this->transformBuilder->resource($data, $transformer, $resourceKey); return $this; }
php
{ "resource": "" }
q255583
ConvertsExceptions.convert
test
protected function convert(Exception $exception, array $convert) { foreach ($convert as $source => $target) { if ($exception instanceof $source) { if (is_callable($target)) { $target($exception); } throw new $target; } } }
php
{ "resource": "" }
q255584
ConvertsExceptions.convertDefaultException
test
protected function convertDefaultException(Exception $exception) { $this->convert($exception, array_diff_key([ AuthenticationException::class => UnauthenticatedException::class, AuthorizationException::class => UnauthorizedException::class, NotFoundHttpException::class => PageNotFoundException::class, ModelNotFoundException::class => PageNotFoundException::class, BaseRelationNotFoundException::class => RelationNotFoundException::class, ValidationException::class => function ($exception) { throw new ValidationFailedException($exception->validator); }, ], array_flip($this->dontConvert))); }
php
{ "resource": "" }
q255585
ConvertsExceptions.renderResponse
test
protected function renderResponse(HttpException $exception): JsonResponse { return app(Responder::class) ->error($exception->errorCode(), $exception->message()) ->data($exception->data()) ->respond($exception->statusCode(), $exception->getHeaders()); }
php
{ "resource": "" }
q255586
Transformation.make
test
public function make($data = null, $transformer = null, string $resourceKey = null): TransformBuilder { return $this->transformBuilder->resource($data, $transformer, $resourceKey)->serializer(new NoopSerializer); }
php
{ "resource": "" }
q255587
CliMenu.configureTerminal
test
protected function configureTerminal() : void { $this->assertTerminalIsValidTTY(); $this->terminal->disableCanonicalMode(); $this->terminal->disableEchoBack(); $this->terminal->disableCursor(); $this->terminal->clear(); }
php
{ "resource": "" }
q255588
CliMenu.addItems
test
public function addItems(array $items) : void { foreach ($items as $item) { $this->items[] = $item; } $this->selectFirstItem(); }
php
{ "resource": "" }
q255589
CliMenu.setItems
test
public function setItems(array $items) : void { $this->selectedItem = null; $this->items = $items; $this->selectFirstItem(); }
php
{ "resource": "" }
q255590
CliMenu.selectFirstItem
test
private function selectFirstItem() : void { if (null === $this->selectedItem) { foreach ($this->items as $key => $item) { if ($item->canSelect()) { $this->selectedItem = $key; break; } } } }
php
{ "resource": "" }
q255591
CliMenu.addCustomControlMapping
test
public function addCustomControlMapping(string $input, callable $callable) : void { if (isset($this->defaultControlMappings[$input]) || isset($this->customControlMappings[$input])) { throw new \InvalidArgumentException('Cannot rebind this input'); } $this->customControlMappings[$input] = $callable; }
php
{ "resource": "" }
q255592
CliMenu.removeCustomControlMapping
test
public function removeCustomControlMapping(string $input) : void { if (!isset($this->customControlMappings[$input])) { throw new \InvalidArgumentException('This input is not registered'); } unset($this->customControlMappings[$input]); }
php
{ "resource": "" }
q255593
CliMenu.display
test
private function display() : void { $this->draw(); $reader = new NonCanonicalReader($this->terminal); $reader->addControlMappings($this->defaultControlMappings); while ($this->isOpen()) { $char = $reader->readCharacter(); if (!$char->isHandledControl()) { $rawChar = $char->get(); if (isset($this->customControlMappings[$rawChar])) { $this->customControlMappings[$rawChar]($this); } continue; } switch ($char->getControl()) { case InputCharacter::UP: case InputCharacter::DOWN: $this->moveSelectionVertically($char->getControl()); $this->draw(); break; case InputCharacter::LEFT: case InputCharacter::RIGHT: $this->moveSelectionHorizontally($char->getControl()); $this->draw(); break; case InputCharacter::ENTER: $this->executeCurrentItem(); break; } } }
php
{ "resource": "" }
q255594
CliMenu.getSelectedItem
test
public function getSelectedItem() : MenuItemInterface { if (null === $this->selectedItem) { throw new \RuntimeException('No selected item'); } $item = $this->items[$this->selectedItem]; return $item instanceof SplitItem ? $item->getSelectedItem() : $item; }
php
{ "resource": "" }
q255595
CliMenu.executeCurrentItem
test
protected function executeCurrentItem() : void { $item = $this->getSelectedItem(); if ($item->canSelect()) { $callable = $item->getSelectAction(); if ($callable) { $callable($this); } } }
php
{ "resource": "" }
q255596
CliMenu.redraw
test
public function redraw(bool $clear = false) : void { if ($clear) { $this->terminal->clear(); } $this->assertOpen(); $this->draw(); }
php
{ "resource": "" }
q255597
CliMenu.draw
test
protected function draw() : void { $frame = new Frame; $frame->newLine(2); if ($this->style->getBorderTopWidth() > 0) { $frame->addRows($this->style->getBorderTopRows()); } if ($this->style->getPaddingTopBottom() > 0) { $frame->addRows($this->style->getPaddingTopBottomRows()); } if ($this->title) { $frame->addRows($this->drawMenuItem(new StaticItem($this->title))); $frame->addRows($this->drawMenuItem(new LineBreakItem($this->style->getTitleSeparator()))); } array_map(function ($item, $index) use ($frame) { $frame->addRows($this->drawMenuItem($item, $index === $this->selectedItem)); }, $this->items, array_keys($this->items)); if ($this->style->getPaddingTopBottom() > 0) { $frame->addRows($this->style->getPaddingTopBottomRows()); } if ($this->style->getBorderBottomWidth() > 0) { $frame->addRows($this->style->getBorderBottomRows()); } $frame->newLine(2); $this->terminal->moveCursorToTop(); foreach ($frame->getRows() as $row) { if ($row == "\n") { $this->terminal->clearLine(); } $this->terminal->write($row); } $this->terminal->clearDown(); $this->currentFrame = $frame; }
php
{ "resource": "" }
q255598
CliMenu.drawMenuItem
test
protected function drawMenuItem(MenuItemInterface $item, bool $selected = false) : array { $rows = $item->getRows($this->style, $selected); if ($item instanceof SplitItem) { $selected = false; } $invertedColoursSetCode = $selected ? $this->style->getInvertedColoursSetCode() : ''; $invertedColoursUnsetCode = $selected ? $this->style->getInvertedColoursUnsetCode() : ''; if ($this->style->getBorderLeftWidth() || $this->style->getBorderRightWidth()) { $borderColour = $this->style->getBorderColourCode(); } else { $borderColour = ''; } return array_map(function ($row) use ($invertedColoursSetCode, $invertedColoursUnsetCode, $borderColour) { return sprintf( "%s%s%s%s%s%s%s%s%s%s%s%s\n", str_repeat(' ', $this->style->getMargin()), $borderColour, str_repeat(' ', $this->style->getBorderLeftWidth()), $this->style->getColoursSetCode(), $invertedColoursSetCode, str_repeat(' ', $this->style->getPaddingLeftRight()), $row, str_repeat(' ', $this->style->getRightHandPadding(mb_strlen(s::stripAnsiEscapeSequence($row)))), $invertedColoursUnsetCode, $borderColour, str_repeat(' ', $this->style->getBorderRightWidth()), $this->style->getColoursResetCode() ); }, $rows); }
php
{ "resource": "" }
q255599
CliMenu.close
test
public function close() : void { $menu = $this; do { $menu->closeThis(); $menu = $menu->getParent(); } while (null !== $menu); $this->tearDownTerminal(); }
php
{ "resource": "" }