_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q12500
MissingCommand.getOldLemmas
train
protected function getOldLemmas($file_lang_path, array $values = []) { if (!is_writable(dirname($file_lang_path))) { $this->error(" > Unable to write file in directory " . dirname($file_lang_path)); die(); } if (!file_exists($file_lang_path)) { $this->info(" > File has been created"); } if (!touch($file_lang_path)) { $this->error(" > Unable to touch file {$file_lang_path}"); die(); } if (!is_readable($file_lang_path)) { $this->error(" > Unable to read file {$file_lang_path}"); die(); } if (!is_writable($file_lang_path)) { $this->error(" > Unable to write in file {$file_lang_path}"); die(); } // Get lang file values $lang = include($file_lang_path); // Parse values $lang = is_array($lang) ? Arr::dot($lang) : []; foreach ($lang as $key => $value) { $values[$this->encodeKey($key)] = $value; } return $values; }
php
{ "resource": "" }
q12501
SqlEngineFactory.build
train
public static function build($pdo, $table) { $mapper = new CacheMapper(new NativeSerializer(), $pdo, $table); return new SqlCacheEngine($mapper); }
php
{ "resource": "" }
q12502
MemberAddress.canCreate
train
public function canCreate($member = null) { if (!$member) { $member = Member::currentUser(); } $extended = $this->extendedCan('canCreate', $member); if ($extended !== null) { return $extended; } if ($member) { return true; } else { return false; } }
php
{ "resource": "" }
q12503
Connector.login
train
public function login($username, $password) { // @ - intentionally, because false is enough if (@ftp_login($this->stream, $username, $password)) { $this->loggedIn = true; return true; } else { return false; } }
php
{ "resource": "" }
q12504
ImageProcessor.text
train
public function text($text, $fontFile, $size, array $rgb = array(0, 0, 0), $corner = self::IMG_CENTER_CORNER, $offsetX = 0, $offsetY = 0, $angle = 0) { $box = imagettfbbox($size, $angle, $fontFile, $text); // Calculate width and height for the text $height = $box[1] - $box[7]; $width = $box[2] - $box[0]; // Calculate positions according to corner's value switch ($corner) { case self::IMG_CENTER_CORNER: $x = floor(($this->width - $width) / 2); $y = floor(($this->height - $height) / 2); break; case self::IMG_LEFT_TOP_CORNER: $x = $offsetX; $y = $offsetY; break; case self::IMG_RIGHT_TOP_CORNER: $x = $this->width - $width - $offsetX; $y = $offsetY; break; case self::IMG_LEFT_BOTTOM_CORNER: $x = $offsetX; $y = $this->height - $height - $offsetY; break; case self::IMG_RIGHT_BOTTOM_CORNER: $x = $this->width - $width - $offsetX; $y = $this->height - $height - $offsetY; break; default: throw new UnexpectedValueException('unsupported corner value supplied'); } $color = imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]); imagettftext($this->image, $size, $angle, $x, $y + $height, $color, $fontFile, $text); return $this; }
php
{ "resource": "" }
q12505
ImageProcessor.flip
train
public function flip($type) { // Initial positioning $x = 0; $y = 0; // Save original dimensions $width = $this->width; $height = $this->height; switch ($type) { case self::IMG_FLIP_BOTH: $x = $this->width - 1; $y = $this->height - 1; $width = -$this->width; $height = -$this->height; break; case self::IMG_FLIP_HORIZONTAL: $x = $this->width - 1; $width = -$this->width; break; case self::IMG_FLIP_VERTICAL: $y = $this->height - 1; $height = -$this->height; break; default: throw new UnexpectedValueException("Invalid flip type's value supplied"); } // Done. Now create a new image $image = imagecreatetruecolor($this->width, $this->height); $this->preserveTransparency($image); imagecopyresampled($image, $this->image, 0, 0, $x, $y, $this->width, $this->height, $width, $height); // Override with new one $this->setImage($image); return $this; }
php
{ "resource": "" }
q12506
ImageProcessor.watermark
train
public function watermark($watermarkFile, $corner = self::IMG_RIGHT_BOTTOM_CORNER, $offsetX = 10, $offsetY = 10) { // The very first thing we gotta do is to load watermark's image file $watermark = new ImageFile($watermarkFile); // Initial positioning $x = 0; $y = 0; // Walk through supported values switch ($corner) { case self::IMG_RIGHT_BOTTOM_CORNER: $x = $this->width - $watermark->getWidth() - $offsetX; $y = $this->height - $watermark->getHeight() - $offsetY; break; case self::IMG_RIGHT_TOP: $x = $this->width - $watermark->getWidth() - $offsetX; $y = $offsetY; break; case self::IMG_LEFT_CORNER: $x = $offsetX; $y = $offsetY; break; case self::IMG_LEFT_BOTTOM_CORNER: $x = $offsetX; $y = $this->height - $watermark->getHeight() - $offsetY; break; case self::CORNER_CENTER: $x = floor(($this->width - $watermark->getWidth()) / 2); $y = floor(($this->height - $watermark->getHeight()) / 2); break; default: throw new UnexpectedValueException(sprintf("Unexpected corner's value provided '%s'", $corner)); } // Done with calculations. Now add a watermark on the original loaded image imagecopy($this->image, $watermark->getImage(), $x, $y, 0, 0, $watermark->getWidth(), $watermark->getHeight()); // Free memory now unset($watermark); return $this; }
php
{ "resource": "" }
q12507
ImageProcessor.blackwhite
train
public function blackwhite() { imagefilter($this->image, \IMG_FILTER_GRAYSCALE); imagefilter($this->image, \IMG_FILTER_CONTRAST, -1000); return $this; }
php
{ "resource": "" }
q12508
ImageProcessor.resize
train
public function resize($x, $y, $proportional = true) { // Check firstly values if ($x === null || $x > $this->width) { $x = $this->width; } if ($y === null || $y > $this->height) { $y = $this->height; } if ($proportional === true) { $height = $y; $width = round($height / $this->height * $this->width); if ($width < $x) { $width = $x; $height = round($width / $this->width * $this->height); } } else { // When no proportionality required, then use target dimensions $width = $x; $height = $y; } // Done calculating. Create a new image in memory $image = imagecreatetruecolor($width, $height); $this->preserveTransparency($image); imagecopyresampled($image, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height); $this->setImage($image); $this->width = $width; $this->height = $height; return $this; }
php
{ "resource": "" }
q12509
ImageProcessor.crop
train
public function crop($width, $height, $startX = null, $startY = null) { if ($width === null) { $width = $this->width; } if ($height === null) { $height = $this->height; } if ($startX === null) { $startX = floor(($this->width - $width) / 2); } if ($startY === null) { $startY = floor(($this->height - $height) / 2); } // Calculate dimensions $startX = max(0, min($this->width, $startX)); $startY = max(0, min($this->height, $startY)); $width = min($width, $this->width - $startX); $height = min($height, $this->height - $startY); $image = imagecreatetruecolor($width, $height); $this->preserveTransparency($image); imagecopyresampled($image, $this->image, 0, 0, $startX, $startY, $width, $height, $width, $height); $this->setImage($image); $this->width = $width; $this->height = $height; return $this; }
php
{ "resource": "" }
q12510
ImageProcessor.thumb
train
public function thumb($width, $height) { $this->resize($width, $height) ->crop($width, $height); return $this; }
php
{ "resource": "" }
q12511
ImageProcessor.rotate
train
public function rotate($degrees) { // Cast to the int, in case we got a numeric string $degrees = (int) $degrees; $this->image = imagerotate($this->image, $degrees, 0); $this->width = imagesx($this->image); $this->height = imagesy($this->image); return $this; }
php
{ "resource": "" }
q12512
ImageProcessor.preserveTransparency
train
private function preserveTransparency($image) { $transparencyColor = array(0, 0, 0); switch ($this->type) { case \IMAGETYPE_GIF: $color = imagecolorallocate($image, $transparencyColor[0], $transparencyColor[1], $transparencyColor[2]); imagecolortransparent($image, $color); imagetruecolortopalette($image, false, 256); break; case \IMAGETYPE_PNG: imagealphablending($image, false); $color = imagecolorallocatealpha($image, $transparencyColor[0], $transparencyColor[1], $transparencyColor[2], 0); imagefill($image, 0, 0, $color); imagesavealpha($image, true); break; } }
php
{ "resource": "" }
q12513
EventManager.attach
train
public function attach($event, Closure $listener) { if (!is_callable($listener)) { throw new InvalidArgumentException(sprintf( 'Second argument must be callable not "%s"', gettype($listener) )); } if (!is_string($event)) { throw new InvalidArgumentException(sprintf( 'First argument must be string, got "%s"', gettype($event) )); } $this->listeners[$event] = $listener; return $this; }
php
{ "resource": "" }
q12514
EventManager.attachMany
train
public function attachMany(array $collection) { foreach ($collection as $event => $listener) { $this->attach($event, $listener); } return $this; }
php
{ "resource": "" }
q12515
EventManager.detach
train
public function detach($event) { if ($this->has($event)) { unset($this->listeners[$event]); } else { throw new RuntimeException(sprintf( 'Cannot detach non-existing event "%s"', $event )); } }
php
{ "resource": "" }
q12516
EventManager.hasMany
train
public function hasMany(array $events) { foreach ($events as $event) { if (!$this->has($event)) { return false; } } return true; }
php
{ "resource": "" }
q12517
EnvTasks.envUp
train
public function envUp($opts = [ 'native' => false, 'no-hostname' => false, 'no-browser' => false ]) { $this->executeCommandHook(__FUNCTION__, 'before'); /** @var EngineType $engine */ $engine = $this->engineInstance(); if ($engine instanceof DockerEngineType) { if ($opts['native']) { $engine->disableDockerSync(); } } $status = $engine->up(); if ($status !== false) { $this->invokeEngineEvent('onEngineUp'); // Add hostname to the system hosts file. if (!$opts['no-hostname']) { $this->addHostName($opts['no-browser']); } } $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12518
EnvTasks.envRebuild
train
public function envRebuild() { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->rebuild(); $this->projectInstance()->rebuildSettings(); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12519
EnvTasks.envDown
train
public function envDown($opts = [ 'include-network' => false, ]) { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->down($opts['include-network']); // Allow projects to react to the engine shutdown. $this->invokeEngineEvent('onEngineDown'); // Remove hostname from the system hosts file. $this->removeHostName(); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12520
EnvTasks.envResume
train
public function envResume() { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->start(); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12521
EnvTasks.envRestart
train
public function envRestart() { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->restart(); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12522
EnvTasks.envReboot
train
public function envReboot($opts = [ 'include-network' => false, ]) { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->reboot($opts['include-network']); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12523
EnvTasks.envHalt
train
public function envHalt() { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->suspend(); $this->executeCommandHook(__FUNCTION__, 'after'); }
php
{ "resource": "" }
q12524
EnvTasks.envInstall
train
public function envInstall() { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->install(); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12525
EnvTasks.envSsh
train
public function envSsh($opts = ['service' => null]) { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->ssh($opts['service']); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12526
EnvTasks.envLogs
train
public function envLogs($opts = ['show' => 'all', 'follow' => false, 'service' => null]) { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->logs($opts['show'], $opts['follow'], $opts['service']); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12527
EnvTasks.envExec
train
public function envExec(array $execute_command, $opts = ['service' => null]) { $this->executeCommandHook(__FUNCTION__, 'before'); $this->engineInstance()->exec( implode(' ', $execute_command), $opts['service'] ); $this->executeCommandHook(__FUNCTION__, 'after'); return $this; }
php
{ "resource": "" }
q12528
EnvTasks.addHostName
train
protected function addHostName($no_browser) { $host = ProjectX::getProjectConfig() ->getHost(); if (!empty($host)) { $hostsfile = (new HostsFile()) ->setLine('127.0.0.1', $host['name']); (new HostsFileWriter($hostsfile))->add(); $this->say( sprintf('Added %s to hosts file.', $host['name']) ); if (!$no_browser && $host['open_on_startup'] == 'true') { $this->taskOpenBrowser('http://' . $host['name']) ->run(); } } return $this; }
php
{ "resource": "" }
q12529
EnvTasks.removeHostName
train
protected function removeHostName() { $host = ProjectX::getProjectConfig() ->getHost(); if (!empty($host)) { $hostsfile = (new HostsFile()) ->setLine('127.0.0.1', $host['name']); (new HostsFileWriter($hostsfile))->remove(); $this->say( sprintf('Removed %s from hosts file.', $host['name']) ); } return $this; }
php
{ "resource": "" }
q12530
EnvTasks.invokeEngineEvent
train
protected function invokeEngineEvent($method) { $project = $this->getProjectInstance(); if ($project instanceof EngineEventInterface) { call_user_func_array([$project, $method], []); } $platform = $this->getPlatformInstance(); if ($platform instanceof EngineEventInterface) { call_user_func_array([$platform, $method], []); } }
php
{ "resource": "" }
q12531
ModelDocument.setFile
train
public function setFile(UploadedFile $file = null) { $this->file = $file; $this->name = $file->getClientOriginalName(); // check if we have an old image path if (isset($this->path)) { // store the old name to delete after the update $this->temp = $this->path; $this->path = null; } else { $this->path = 'initial'; } }
php
{ "resource": "" }
q12532
ModuleManager.exists
train
public static function exists($string) { $instance = self::getInstance(); foreach ($instance->getModules() as $module) { if ($module->title === $string) { return true; } } return false; }
php
{ "resource": "" }
q12533
ModuleManager.existsController
train
public static function existsController($key) { $instance = self::getInstance(); foreach ($instance->getModules() as $module) { foreach ($module->getControllers() as $controller => $file) { if ($key == $controller) { return true; } } } return false; }
php
{ "resource": "" }
q12534
ModuleManager.run
train
public function run($url = null, $method = null) { $request = new Request($method, $url); try { // foreach ($this->modules as $module) { // // } Profiler::start('router'); if ($match = $this->router->match($url, $method)) { if ($match['name'] === 'handleFilesystem') { Profiler::stop('router'); return $this->handleFilesystem($match['params'], $request); } else { $target = $match['target']; $module = $target[0]; if ($module instanceof Module) { if ($this->isEnabled($module->title)) { $this->runningModule = $module; $controller = $target[1]; $request->setParams($match['params']); Profiler::stop('router'); return $module->run($controller, $request); } else { Profiler::stop('router'); return $this->mainModule->run(new ErrorController("This module is disabled by your policy"), $request); } } } } Profiler::stop('router'); return $this->mainModule->run(new ErrorController("Controller for '$url' not found. " . $this->getRoutes()), $request); } catch (\Exception $ex) { Events::dispatch('onException', $ex); return $this->mainModule->run(new ExceptionController($ex), $request); } catch (\Throwable $ex) { Events::dispatch('onError', $ex); return $this->mainModule->run(new ExceptionController($ex), $request); } }
php
{ "resource": "" }
q12535
ModuleManager.getRoutes
train
public function getRoutes() { if ($this->config['app']['debug']) { $html = '<pre>'; $result = array(); foreach ($this->modules as $module) { $list = $module->getControllersUrlRoutes(); $result = array_merge($list, $result); } $html .= implode("\n", $result); $html .= '</pre>'; return $html; } return ""; }
php
{ "resource": "" }
q12536
ModuleManager.handleFilesystem
train
public function handleFilesystem($args, $request) { $file = urldecode($args['name']); $filesystem = new Filesystem($file); if ($filesystem->exists()) { if ($filesystem->isPublic()) { header('Content-Type: ' . mime_content_type($filesystem->getAbsolutePath())); $filesystem->read(true); die(); } else { return $this->mainModule->run(new ErrorController('Este archivo no es descargable'), $request); } } else { return $this->mainModule->run(new ErrorController('No se ha encontrado este archivo!'), $request); } }
php
{ "resource": "" }
q12537
ExtraAdminController.trashAction
train
public function trashAction() { if (false === $this->admin->isGranted('LIST')) { throw new AccessDeniedException(); } $em = $this->getDoctrine()->getManager(); $em->getFilters()->disable('softdeleteable'); $em->getFilters()->enable('softdeleteabletrash'); $em->getFilters()->getFilter("softdeleteabletrash")->enableForEntity($this->admin->getClass()); $datagrid = $this->admin->getDatagrid(); $formView = $datagrid->getForm()->createView(); // set the theme for the current Admin Form $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme()); return $this->render($this->admin->getTemplate('trash'), array( 'action' => 'trash', 'form' => $formView, 'datagrid' => $datagrid, 'csrf_token' => $this->getCsrfToken('sonata.batch'), )); }
php
{ "resource": "" }
q12538
Paginator.formatToArrayStandard
train
function formatToArrayStandard($route = null,array $parameters = array()) { $links = array( 'self' => array('href' => ''), 'first' => array('href' => ''), 'last' => array('href' => ''), 'next' => array('href' => ''), 'previous' => array('href' => ''), ); $paginator = array( 'currentPage' => $this->getCurrentPage(), 'maxPerPage' => $this->getMaxPerPage(), 'totalPages' => $this->getNbPages(), 'totalResults' => $this->getNbResults(), ); $pageResult = $this->getCurrentPageResults(); if(is_array($pageResult)){ $results = $pageResult; }else{ $results = $this->getCurrentPageResults()->getArrayCopy(); } return array( 'links' => $this->getLinks($route,$parameters), 'meta' => $paginator, 'data' => $results, ); }
php
{ "resource": "" }
q12539
Paginator.formatToArrayDataTables
train
function formatToArrayDataTables($route = null,array $parameters = array()) { $results = $this->getCurrentPageResults()->getArrayCopy(); $data = array( 'draw' => $this->draw, 'recordsTotal' => $this->getNbResults(), 'recordsFiltered' => $this->getNbResults(), 'data' => $results, '_links' => $this->getLinks($route,$parameters), ); return $data; }
php
{ "resource": "" }
q12540
Paginator.toArray
train
function toArray($route = null,array $parameters = array(),$format = null) { if($format === null){ $format = $this->defaultFormat; } if(in_array($format, $this->formatArray)){ $method = 'formatToArray'.ucfirst($format); return $this->$method($route,$parameters); } }
php
{ "resource": "" }
q12541
Paginator.generateUrl
train
protected function generateUrl($route,array $parameters){ return $this->container->get('router')->generate($route, $parameters, Router::ABSOLUTE_URL); }
php
{ "resource": "" }
q12542
Paginator.getLinks
train
protected function getLinks($route,array $parameters = array()){ $links = array(); if($route != null){ $baseParams = $_GET; unset($baseParams["page"]); $parameters = array_merge($parameters,$baseParams); $links['first']['href'] = $this->generateUrl($route, array_merge($parameters, array('page' => 1))); $links['self']['href'] = $this->generateUrl($route, array_merge($parameters, array('page' => $this->getCurrentPage()))); $links['last']['href'] = $this->generateUrl($route, array_merge($parameters, array('page' => $this->getNbPages()))); if($this->hasPreviousPage()){ $links['previous']['href'] = $this->generateUrl($route, array_merge($parameters, array('page' => $this->getPreviousPage()))); } if($this->hasNextPage()){ $links['next']['href'] = $this->generateUrl($route, array_merge($parameters, array('page' => $this->getNextPage()))); } } return $links; }
php
{ "resource": "" }
q12543
Paginator.setRequest
train
function setRequest(\Symfony\Component\HttpFoundation\Request $request) { $this->request = $request; if(self::FORMAT_ARRAY_DATA_TABLES == $this->defaultFormat){ //Ejemplo start(20) / length(10) = 2 $start = (int)$request->get("start",0);//Elemento inicio $length = (int)$request->get("length",10);//Cantidad de elementos por pagina $this->draw = $request->get("draw", $this->draw) + 1;//No cache if($start > 0){ $page = (int)($start / $length); $page = $page + 1; }else{ $page = 1; } if(!is_int($length)){ $length = 10; } if(!is_int($page)){ $page = 1; } $this->setMaxPerPage($length); $this->setCurrentPage($page); }else if(self::FORMAT_ARRAY_STANDARD == $this->defaultFormat){ $page = (int)$request->get("page",1);//Elemento inicio $maxPerPage = (int)$request->get("maxPerPage",10);//Elemento inicio $this->setMaxPerPage($maxPerPage); $totalPages = $this->getNbPages(); if($page > $this->getNbPages()){ $page = $totalPages; } $this->setCurrentPage($page); } }
php
{ "resource": "" }
q12544
Filesystem.allocate
train
public static function allocate($filename = null, $extension = ".rnd", $folder = null) { if ($filename === null) { $filename = sha1(time() . "_" . microtime(true)); } if ($folder) { $ffolder = new Filesystem($folder); if (!$ffolder->exists()) { $ffolder->mkdir(); } } $file = new Filesystem($folder . '/' . $filename . $extension); //$this->getStorage() . "/{$filename}{$extension}"; return $file; }
php
{ "resource": "" }
q12545
Filesystem.getFilesystemFolder
train
public function getFilesystemFolder() { $config = Bootstrap::getSingleton()->getConfig(); if (isset($config['app']['filesystem'])) { return Bootstrap::getSingleton()->getDirectory() . '/' . $config['app']['filesystem']; } return Bootstrap::getSingleton()->getDirectory() . '/filesystem'; }
php
{ "resource": "" }
q12546
Filesystem.url
train
public function url($expires = null) { $this->setPublic($expires); return get_protocol() . $_SERVER['HTTP_HOST'] . '/_raw/' . $this->file; }
php
{ "resource": "" }
q12547
PimpleDumper._writePHPStorm
train
protected function _writePHPStorm($map, $className) { $fileName = $this->_root . DIRECTORY_SEPARATOR . self::FILE_PHPSTORM; if (is_dir($fileName)) { $fileName .= DIRECTORY_SEPARATOR . 'pimple.meta.php'; } $list = array(); foreach ($map as $data) { if ($data['type'] === 'class') { $list[] = " '{$data['name']}' instanceof {$data['value']},"; } } $tmpl = array( '<?php', '/**', ' * ProcessWire PhpStorm Meta', ' *', ' * This file is not a CODE, it makes no sense and won\'t run or validate', ' * Its AST serves PhpStorm IDE as DATA source to make advanced type inference decisions.', ' * ', ' * @see https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata', ' */', '', 'namespace PHPSTORM_META {', '', ' $STATIC_METHOD_TYPES = [', ' new \\' . $className . ' => [', ' \'\' == \'@\',', implode("\n", $list), ' ],', ' ];', '', '}', '', ); $content = implode("\n", $tmpl); $this->_updateFile($fileName, $content); return $fileName; }
php
{ "resource": "" }
q12548
PimpleDumper._updateFile
train
protected function _updateFile($fileName, $content) { $oldContent = null; if (file_exists($fileName)) { $oldContent = file_get_contents($fileName); } if ($content !== $oldContent) { file_put_contents($fileName, $content); } return $fileName; }
php
{ "resource": "" }
q12549
ForwardableHandler.forwardMessage
train
public function forwardMessage($toChatId, bool $disableNotification = false): void { $m = $this->bot->forwardMessage(); $m->setChatId($toChatId); $m->setFromChatId($this->message->getChat()->getId()); $m->setMessageId($this->message->getMessageId()); $m->setDisableNotification($disableNotification); $m->send(); }
php
{ "resource": "" }
q12550
JsonStorage.load
train
public function load() { // Initial state, is always empty array $data = array(); // Alter $data in case it exists and its valid if ($this->storageAdapter->has($this->key)) { $target = $this->serializer->unserialize($this->storageAdapter->get($this->key)); // If $target is null, then data either is damaged or doesn't exist, otherwise it's okay if ($target !== null) { $data = $target; } } return $data; }
php
{ "resource": "" }
q12551
JsonStorage.save
train
public function save(array $data) { // This is what we're going to store $seriaziledData = $this->serializer->serialize($data); $this->storageAdapter->set($this->key, $seriaziledData, $this->ttl); return true; }
php
{ "resource": "" }
q12552
JsonStorage.clear
train
public function clear() { if ($this->storageAdapter->has($this->key)) { $this->storageAdapter->remove($this->key); } }
php
{ "resource": "" }
q12553
FtpFactory.build
train
public static function build($host, $username = null, $password = null, $timeout = 90, $port = 21, $ssl = false) { $connector = new Connector($host, $timeout, $port, $ssl); if (!$connector->connect()) { throw new RuntimeException('Cannot connect to remote FTP server'); } if ($username !== null && $password !== null) { if (!$connector->login($username, $password)) { throw new LogicException('Invalid combination of username and password provided'); } } return new FtpManager($connector); }
php
{ "resource": "" }
q12554
TableType.isColumn
train
protected function isColumn(ResolvedBlockTypeInterface $type) { if ('table_column' === $type->getBlockPrefix()) { return true; } if (null !== $type->getParent()) { return $this->isColumn($type->getParent()); } return false; }
php
{ "resource": "" }
q12555
SecurityHandler.checkSecurity
train
public function checkSecurity($rol,$parameters = null) { if($rol === null){ throw $this->createAccessDeniedHttpException($this->trans($this->genericMessage)); } $roles = $rol; if(!is_array($rol)){ $roles = array($rol); } $valid = $this->getSecurityContext()->isGranted($roles,$parameters); foreach ($roles as $rol) { if(!$valid){ throw $this->createAccessDeniedHttpException($this->buildMessage($rol)); } $methodValidMap = $this->getMethodValidMap(); if(isset($methodValidMap[$rol])){ $method = $methodValidMap[$rol]; $valid = call_user_func_array(array($this,$method),array($rol,$parameters)); } } }
php
{ "resource": "" }
q12556
SecurityHandler.buildMessage
train
private function buildMessage($rol,$prefix = '403') { return $this->trans(sprintf('%s.%s.%s', $this->prefixMessage,$prefix,strtolower($rol))); }
php
{ "resource": "" }
q12557
SecurityHandler.setFlash
train
protected function setFlash($type,$message,$parameters = array(),$domain = 'flashes') { return $this->container->get('session')->getBag('flashes')->add($type,$message); }
php
{ "resource": "" }
q12558
AbstractImageManagerFactory.build
train
final public function build() { return new ImageManager($this->getPath(), $this->getRootDir(), $this->getRootUrl(), $this->getConfig()); }
php
{ "resource": "" }
q12559
DiggStyle.getPageNumbers
train
public function getPageNumbers(array $pages, $current) { $result = array(); $amount = count($pages); $start = 3; if ($amount > $start) { // this specifies the range of pages we want to show in the middle $min = max($current - 2, 2); $max = min($current + 2, $amount - 1); // we always show the first page $result[] = 1; // we're more than one space away from the beginning, so we need a separator if ($min > 2) { $result[] = '...'; } // generate the middle numbers for ($i = $min; $i < $max + 1; $i++) { $result[] = $i; } // we're more than one space away from the end, so we need a separator if ($max < $amount - 1) { $result[] = '...'; } // we always show the last page, which is the same as amount $result[] = $amount; return $result; } else { // It's not worth using a style adapter, because amount of pages is less than 3 return range(1, $start); } }
php
{ "resource": "" }
q12560
ControllerFactory.build
train
public function build($controller, $action, array $options) { $class = Ns::normalize($controller); // PSR-0 Autoloader will do its own job by default when calling class_exists() function if (class_exists($class)) { // Target module which is going to be instantiated $module = Ns::extractVendorNs($controller); $controller = new $class($this->serviceLocator, $module, $options); if (method_exists($controller, 'initialize')) { $controller->initialize($action); if ($controller->isHalted()) { throw new DomainException('Controller halted its execution due to route options mismatch'); } return $controller; } else { throw new RuntimeException('A base controller must be inherited'); } } else { // A name does not match PSR-0 trigger_error(sprintf( 'Controller does not exist : "%s" or it does not match PSR-0', $class), E_USER_ERROR ); } }
php
{ "resource": "" }
q12561
RoutesManager.getRoutesFromIndex
train
private function getRoutesFromIndex (&$routes, &$routesIndex, &$requestMethod, &$requestPathParts, $requestPathIndex = 0) { if (!empty($requestPathParts[$requestPathIndex])) { $requestPathPart = $requestPathParts[$requestPathIndex]; if (array_key_exists($requestPathPart, $routesIndex)) { $this->getRoutesFromIndex($routes,$routesIndex[$requestPathPart], $requestMethod, $requestPathParts, $requestPathIndex + 1); } if (array_key_exists(self::ROUTE_PARAMETER_WILDCARD, $routesIndex)) { $this->getRoutesFromIndex($routes,$routesIndex[self::ROUTE_PARAMETER_WILDCARD], $requestMethod, $requestPathParts, $requestPathIndex + 1); } } else if (array_key_exists(self::ROUTE_ACTIONS_KEY, $routesIndex)) { $testRoutes = &$routesIndex[self::ROUTE_ACTIONS_KEY]; if (array_key_exists($requestMethod, $testRoutes)) { $this->getRoutesFromIndexActions($routes,$testRoutes[$requestMethod], $requestMethod,$requestPathParts); } if (array_key_exists(self::ROUTE_GENERIC_METHOD, $testRoutes)) { $this->getRoutesFromIndexActions($routes,$testRoutes[self::ROUTE_GENERIC_METHOD], $requestMethod, $requestPathParts); } } if (array_key_exists(self::ROUTE_GENERIC_ACTIONS_KEY, $routesIndex)) { $testRoutes = &$routesIndex[self::ROUTE_GENERIC_ACTIONS_KEY]; if (array_key_exists($requestMethod, $testRoutes)) { $this->getRoutesFromIndexActions($routes,$testRoutes[$requestMethod], $requestMethod, $requestPathParts); } if (array_key_exists(self::ROUTE_GENERIC_METHOD, $testRoutes)) { $this->getRoutesFromIndexActions($routes,$testRoutes[self::ROUTE_GENERIC_METHOD], $requestMethod, $requestPathParts); } } }
php
{ "resource": "" }
q12562
RoutesManager.getRoutesFromIndexActions
train
private function getRoutesFromIndexActions (&$routes, array &$routeActions, &$requestMethod, array &$requestPathParts) { foreach ($routeActions as $routeData) { $routePath = $routeData[0]; $routeAction = $routeData[1]; $routeParameters = []; if (strpos($routePath, self::ROUTE_PARAMETER_PREFIX) !== false || strpos($routePath, self::ROUTE_GENERIC_PATH) !== false) { $routePathParts = explode(self::ROUTE_PATH_SEPARATOR, trim($routePath, self::ROUTE_PATH_SEPARATOR));; for ($i = 0; $i < sizeof($routePathParts); $i++) { $routePathPart = $routePathParts[$i]; if ($routePathPart == self::ROUTE_GENERIC_PATH) { $path = array_slice($requestPathParts, $i); $routeParameters[self::ROUTE_PATH_PARAMETER_NAME] = $path; break; } else if ($routePathPart[0] == self::ROUTE_PARAMETER_PREFIX) { $parameterName = substr($routePathPart, 1); $parameterValue = $requestPathParts[$i]; $routeParameters[$parameterName] = $parameterValue; } } } if ($routeAction instanceof RouteGenerator) { $route = $routeAction->generateRoute($requestMethod, isset($path)?$path : $requestPathParts); if ($route) { $routes[] = $route; } } else { $routes[] = new Route($routeAction, $routeParameters); } } }
php
{ "resource": "" }
q12563
DynamicDoctrineChoiceLoader.getRealValues
train
protected function getRealValues(array $values, $value = null) { $value = $this->getCallableValue($value); foreach ($values as &$val) { if (\is_object($val) && \is_callable($value)) { $val = \call_user_func($value, $val); } } return $values; }
php
{ "resource": "" }
q12564
GoogleTasks.listTasklists
train
public function listTasklists( array $queryParameters = [] ): array { $parameters = [ 'maxResults' => 100, ]; $parameters = array_merge($parameters, $queryParameters); return $this ->taskService ->tasklists ->listTasklists($parameters) ->getItems(); }
php
{ "resource": "" }
q12565
GoogleTasks.listTasks
train
public function listTasks( string $taskListId, Carbon $dueMin = null, array $queryParameters = [] ): array { $parameters = [ 'showCompleted' => false, 'showDeleted' => true, 'showHidden' => true, ]; if (is_null($dueMin)) { $dueMin = Carbon::now()->startOfDay(); } $parameters['dueMin'] = $dueMin->format(DateTime::RFC3339); $parameters = array_merge($parameters, $queryParameters); return $this ->taskService ->tasks ->listTasks($taskListId, $parameters) ->getItems(); }
php
{ "resource": "" }
q12566
GoogleTasks.getTask
train
public function getTask(string $taskId): Google_Service_Tasks { return $this->service->tasks->get($this->tasklist, $taskId); }
php
{ "resource": "" }
q12567
GoogleTasks.insertTask
train
public function insertTask($task): Google_Service_Tasks { if ($task instanceof Tasks) { $task = $task->googleTasks; } return $this->service->tasks->insert($this->tasklist, $task); }
php
{ "resource": "" }
q12568
GoogleTasks.deleteTask
train
public function deleteTask($taskId) { if ($taskId instanceof Tasks) { $taskId = $taskId->id; } $this->service->tasks->delete($this->tasklist, $taskId); }
php
{ "resource": "" }
q12569
Input.getFiles
train
public function getFiles($name = null) { if ($name !== null) { if (!array_key_exists($name, $this->files)) { throw new RuntimeException(sprintf( 'Attempted to access non-existing field %s', $name )); } return $this->hydrateAll($this->files[$name]); } else { return $this->hydrateAll($this->files); } }
php
{ "resource": "" }
q12570
Input.hydrateAll
train
private function hydrateAll(array $files) { foreach ($files as $name => $file) { // Recursive protection if (!is_array($file)) { continue; } foreach ($file as $key => $value) { if (is_array($value)) { // Recursive call $files[$name] = call_user_func(array($this, __FUNCTION__), $files[$name]); } else { $files[$name] = $this->hydrate($file); } } } return $files; }
php
{ "resource": "" }
q12571
Input.hydrate
train
private function hydrate(array $file) { $entity = new FileEntity(); $entity->setType($file['type']) ->setName($file['name']) ->setTmpName($file['tmp_name']) ->setSize($file['size']) ->setError($file['error']); return $entity; }
php
{ "resource": "" }
q12572
Input.removeBrokenFiles
train
private function removeBrokenFiles(array $files) { // Recursive logic to replace broken arrays with empty ones (which to be removed later) if (isset($files['error'])) { return $files['error'] == 4 ? array() : $files; } foreach ($files as $key => $value) { // Recursive call $files[$key] = call_user_func(array($this, __FUNCTION__), $value); } // Now remove empty arrays return array_filter($files); }
php
{ "resource": "" }
q12573
Routes.handleRequestNotFound
train
private static function handleRequestNotFound () { $response = get_response(); $response->clear(); $response->statusCode(Response::HTTP_NOT_FOUND); $notFoundRoutes = self::$notFoundRoutes->getRoutes(); if (!empty($notFoundRoutes)) { foreach ($notFoundRoutes as $notFoundRoute) { $routeResult = self::executeAction($notFoundRoute->getAction(), array_merge($_REQUEST, $notFoundRoute->getParameters())); if (isset($routeResult)) { $response->content($routeResult); } } $response->send(); } else { handle_error_code(Response::HTTP_NOT_FOUND); } }
php
{ "resource": "" }
q12574
KernelFactory.build
train
public static function build(array $config) { $input = new Input(); $input->setQuery($_GET) ->setPost($_POST) ->setCookie($_COOKIE) ->setFiles($_FILES) ->setServer($_SERVER) ->setEnv($_ENV) ->setRequest($_REQUEST); return new Kernel($input, $config); }
php
{ "resource": "" }
q12575
ThumbFactory.build
train
public function build($dir, $quality, array $options = array()) { // Alter default quality on demand if (isset($options['quality'])) { $quality = $options['quality']; } return new Thumb($dir, $options['dimensions'], $quality); }
php
{ "resource": "" }
q12576
SqlConfigService.store
train
public function store($module, $name, $value) { $this->initializeOnDemand(); if (!$this->has($module, $name)) { if ($this->configMapper->insert($module, $name, $value)) { $this->arrayConfig->add($module, $name, $value); return true; } } else { if ($this->configMapper->update($module, $name, $value)) { $this->arrayConfig->update($module, $name, $value); return true; } } // By default return false; }
php
{ "resource": "" }
q12577
SqlConfigService.storeModule
train
public function storeModule($module, array $vars) { foreach ($vars as $key => $value) { if (!$this->store($module, $key, $value)) { return false; } } return true; }
php
{ "resource": "" }
q12578
SqlConfigService.get
train
public function get($module, $name, $default = false) { $this->initializeOnDemand(); return $this->arrayConfig->get($module, $name, $default); }
php
{ "resource": "" }
q12579
SqlConfigService.has
train
public function has($module, $name) { $this->initializeOnDemand(); return $this->arrayConfig->has($module, $name); }
php
{ "resource": "" }
q12580
SqlConfigService.removeAll
train
public function removeAll() { $this->initializeOnDemand(); if ($this->configMapper->truncate()) { $this->arrayConfig->clear(); return true; } else { return false; } }
php
{ "resource": "" }
q12581
SqlConfigService.remove
train
public function remove($module, $name) { $this->initializeOnDemand(); if ($this->exists($module, $name) && $this->configMapper->delete($module, $name)) { $this->arrayConfig->remove($module, $name); return true; } else { return false; } }
php
{ "resource": "" }
q12582
SqlConfigService.removeAllByModule
train
public function removeAllByModule($module) { $this->initializeOnDemand(); if ($this->arrayConfig->hasModule($module) && $this->configMapper->deleteAllByModule($module)) { $this->arrayConfig->removeAllByModule($module); return true; } else { return false; } }
php
{ "resource": "" }
q12583
GitAuthorExtractor.isDirtyFile
train
private function isDirtyFile($path, $git) { if (!\is_file($path)) { return false; } $status = (array) $git->status()->short()->getIndexStatus(); $relPath = (string) \substr($path, (\strlen($git->getRepositoryPath()) + 1)); if (isset($status[$relPath]) && $status[$relPath]) { return true; } return false; }
php
{ "resource": "" }
q12584
GitAuthorExtractor.getAuthorListFrom
train
private function getAuthorListFrom() { $filePath = $this->getFilePathCollection($this->currentPath); $authors = []; foreach ((array) $filePath['commits'] as $commit) { if ($this->isMergeCommit($commit) || isset($authors[\md5($commit['name'])]) ) { continue; } $authors[\md5($commit['name'])] = $commit; } if (isset($filePath['pathHistory'])) { foreach ((array) $filePath['pathHistory'] as $pathHistory) { foreach ((array) $pathHistory['commits'] as $commitHistory) { if ($this->isMergeCommit($commitHistory) || isset($authors[\md5($commitHistory['name'])]) ) { continue; } $authors[\md5($commitHistory['name'])] = $commitHistory; } } } return $authors; }
php
{ "resource": "" }
q12585
GitAuthorExtractor.collectFilesWithCommits
train
public function collectFilesWithCommits(GitRepository $git) { // git show --format="%H" --quiet $lastCommitId = $git->show()->format('%H')->execute('--quiet'); $cacheId = \md5(__FUNCTION__ . $lastCommitId); if ($this->cachePool->has($cacheId)) { $fromCache = $this->cachePool->get($cacheId); $this->commitCollection = $fromCache['commitCollection']; $this->filePathMapping = $fromCache['filePathMapping']; $this->filePathCollection = $fromCache['filePathCollection']; return; } $commitCollection = []; $filePathMapping = []; $filePathCollection = []; $this->prepareCommitCollection( $git, $this->fetchAllCommits($git, $lastCommitId), $commitCollection, $filePathMapping, $filePathCollection ); $this->cachePool->set( $cacheId, [ 'commitCollection' => $commitCollection, 'filePathMapping' => $filePathMapping, 'filePathCollection' => $filePathCollection ] ); $this->commitCollection = $commitCollection; $this->filePathMapping = $filePathMapping; $this->filePathCollection = $filePathCollection; }
php
{ "resource": "" }
q12586
GitAuthorExtractor.prepareCommitCollection
train
private function prepareCommitCollection( GitRepository $git, array $logList, array &$commitCollection, array &$filePathMapping, array &$filePathCollection ) { foreach ($logList as $log) { $currentCacheId = \md5(__FUNCTION__ . $log['commit']); if ($this->cachePool->has($currentCacheId)) { $fromCurrentCache = $this->cachePool->get($currentCacheId); $commitCollection = \array_merge($filePathMapping, $fromCurrentCache['commitCollection']); $filePathMapping = \array_merge($filePathMapping, $fromCurrentCache['filePathMapping']); $filePathCollection = \array_merge($filePathCollection, $fromCurrentCache['filePathCollection']); break; } $matches = $this->matchFileInformation($this->fetchNameStatusFromCommit($log['commit'], $git)); if (!\count($matches)) { continue; } $changeCollection = []; foreach ($matches as $match) { $changeCollection[] = \array_filter(\array_filter($match), 'is_string', ARRAY_FILTER_USE_KEY); } $this->prepareChangeCollection( $log, $changeCollection, $commitCollection, $filePathMapping, $filePathCollection ); } }
php
{ "resource": "" }
q12587
GitAuthorExtractor.prepareChangeCollection
train
private function prepareChangeCollection( array $commit, array $changeCollection, array &$commitCollection, array &$filePathMapping, array &$filePathCollection ) { foreach ($changeCollection as $change) { if (!isset($commit['containedPath'])) { $commit['containedPath'] = []; } if (!isset($commit['information'])) { $commit['information'] = []; } if (isset($change['criteria'])) { $changeToHash = \md5($change['to']); $changeFromHash = \md5($change['from']); $commit['containedPath'][$changeToHash] = $change['to']; $commit['information'][$changeToHash] = $change; $filePathMapping[$changeToHash] = $change['to']; $filePathMapping[$changeFromHash] = $change['from']; $filePathCollection[$changeToHash]['commits'][$commit['commit']] = $commit; $filePathCollection[$changeFromHash]['commits'][$commit['commit']] = $commit; $commitCollection[$commit['commit']] = $commit; continue; } $fileHash = \md5($change['file']); $commit['containedPath'][$fileHash] = $change['file']; $commit['information'][$fileHash] = $change; $filePathMapping[$fileHash] = $change['file']; $filePathCollection[$fileHash]['commits'][$commit['commit']] = $commit; $commitCollection[$commit['commit']] = $commit; } }
php
{ "resource": "" }
q12588
GitAuthorExtractor.getFilePathCollection
train
private function getFilePathCollection($path) { $key = \array_flip($this->filePathMapping)[$path]; return $this->filePathCollection[$key]; }
php
{ "resource": "" }
q12589
GitAuthorExtractor.setFilePathCollection
train
private function setFilePathCollection($path, array $data) { $key = \array_flip($this->filePathMapping)[$path]; $this->filePathCollection[$key] = $data; }
php
{ "resource": "" }
q12590
GitAuthorExtractor.countMergeCommits
train
private function countMergeCommits(array $commitList) { $count = 0; foreach ($commitList as $filePathCommit) { if (!$this->isMergeCommit($filePathCommit)) { continue; } $count++; } return $count; }
php
{ "resource": "" }
q12591
GitAuthorExtractor.buildFileHistory
train
private function buildFileHistory(GitRepository $git) { $filePath = $this->getFilePathCollection($this->currentPath); // If the commit history only merges, // then use the last merge commit for find the renaming file for follow the history. if (\count((array) $filePath['commits']) === $this->countMergeCommits($filePath['commits'])) { $commit = $filePath['commits'][\array_reverse(\array_keys($filePath['commits']))[0]]; if ($this->isMergeCommit($commit)) { $parents = \explode(' ', $commit['parent']); $arguments = [ $git->getConfig()->getGitExecutablePath(), 'diff', $commit['commit'], $parents[1], '--diff-filter=R', '--name-status', '--format=', '-M' ]; // git diff currentCommit rightCommit --diff-filter=R --name-status --format='' -M $matches = $this->matchFileInformation($this->runCustomGit($arguments, $git)); foreach ($matches as $match) { if (!\in_array($this->currentPath, $match)) { continue; } $this->currentPath = $match['to']; $filePath = $this->getFilePathCollection($this->currentPath); break; } } } $fileHistory = $this->fetchFileHistory($this->currentPath, $git); if (!\count($fileHistory)) { return; } foreach ($fileHistory as $pathHistory) { $filePath['pathHistory'][\md5($pathHistory)] = $this->getFilePathCollection($pathHistory); } $this->setFilePathCollection($this->currentPath, $filePath); }
php
{ "resource": "" }
q12592
GitAuthorExtractor.getFileContent
train
private function getFileContent($search, GitRepository $git) { $cacheId = \md5(__FUNCTION__ . $search); if (!$this->cachePool->has($cacheId)) { $fileContent = $git->show()->execute($search); $this->cachePool->set($cacheId, $fileContent); return $fileContent; } return $this->cachePool->get($cacheId); }
php
{ "resource": "" }
q12593
GitAuthorExtractor.fetchNameStatusFromCommit
train
private function fetchNameStatusFromCommit($commitId, GitRepository $git) { $arguments = [ $git->getConfig()->getGitExecutablePath(), 'show', $commitId, '-M', '--name-status', '--format=' ]; // git show $commitId -M --name-status --format='' return $this->runCustomGit($arguments, $git); }
php
{ "resource": "" }
q12594
GitAuthorExtractor.fetchCurrentCommit
train
private function fetchCurrentCommit(GitRepository $git) { return \json_decode( \sprintf( '[%s]', // git show --format=$this->logFormat() --quiet $git->show()->format($this->logFormat())->execute('--quiet') ), true ); }
php
{ "resource": "" }
q12595
GitAuthorExtractor.fetchAllCommits
train
private function fetchAllCommits(GitRepository $git) { $currentCommit = $this->fetchCurrentCommit($git); $cacheId = \md5(__FUNCTION__ . \serialize($currentCommit)); if (!$this->cachePool->has($cacheId)) { $logList = \json_decode( \sprintf( '[%s]', \trim( // git log --simplify-merges --format=$this->logFormat() $git->log()->simplifyMerges()->format($this->logFormat() . ',')->execute(), ',' ) ), true ); $this->cachePool->set($cacheId, $logList); return $logList; } return $this->cachePool->get($cacheId); }
php
{ "resource": "" }
q12596
GitAuthorExtractor.fetchFileHistory
train
private function fetchFileHistory($path, GitRepository $git) { $fileHistory = []; foreach ($this->fetchCommitCollectionByPath($path, $git) as $logItem) { // If the renaming/copy to not found in the file history, then continue the loop. if (\count($fileHistory) && !\in_array($logItem['to'], $fileHistory)) { continue; } // If the file history empty (also by the start for the detection) and the to path not exactly the same // with the same path, then continue the loop. if (($logItem['to'] !== $path) && !\count($fileHistory)) { continue; } $this->executeFollowDetection($logItem, $fileHistory, $git); } return $fileHistory; }
php
{ "resource": "" }
q12597
GitAuthorExtractor.fetchCommitCollectionByPath
train
private function fetchCommitCollectionByPath($path, GitRepository $git) { // git log --follow --name-status --format='%H' -- $path $log = $git->log()->follow()->revisionRange('--name-status')->revisionRange('--format=%H')->execute($path); \preg_match_all( "/^(?'commit'.*)\n+(?'criteria'[RC])(?'index'[\d]{3})\t(?'from'.+)\t(?'to'.+)\n/m", $log, $matches, PREG_SET_ORDER ); if (!\count($matches)) { return []; } $logCollection = []; foreach ((array) $matches as $match) { $logCollection[] = \array_filter($match, 'is_string', ARRAY_FILTER_USE_KEY); } return $logCollection; }
php
{ "resource": "" }
q12598
GitAuthorExtractor.executeFollowDetection
train
private function executeFollowDetection(array $logItem, array &$fileHistory, GitRepository $git) { $currentCommit = $this->commitCollection[$logItem['commit']]; if (($logItem['index'] <= 70) && \in_array($logItem['criteria'], ['R', 'C'])) { if (isset($currentCommit['information'][\md5($logItem['to'])])) { $pathInformation = $currentCommit['information'][\md5($logItem['to'])]; if (isset($pathInformation['status']) && ($pathInformation['status'] === 'A')) { return; } } } $this->renamingDetection($logItem, $currentCommit, $fileHistory, $git); $this->copyDetection($logItem, $fileHistory, $git); }
php
{ "resource": "" }
q12599
GitAuthorExtractor.renamingDetection
train
private function renamingDetection(array $logItem, array $currentCommit, array &$fileHistory, GitRepository $git) { if ($logItem['criteria'] !== 'R') { return; } if ((int) $logItem['index'] >= 75) { $fileHistory[\md5($logItem['from'])] = $logItem['from']; return; } $fromFileContent = $this->getFileContent($currentCommit['parent'] . ':' . $logItem['from'], $git); $toFileContent = $this->getFileContent($logItem['commit'] . ':' . $logItem['to'], $git); $tempFrom = $this->createTempFile($logItem['commit'] . ':' . $logItem['from'], $fromFileContent); $tempTo = $this->createTempFile($logItem['commit'] . ':' . $logItem['to'], $toFileContent); $detector = new Detector(new DefaultStrategy()); $result = $detector->copyPasteDetection([$tempFrom, $tempTo], 2, 7); if (!$result->count()) { return; } $fileHistory[\md5($logItem['from'])] = $logItem['from']; }
php
{ "resource": "" }