protected function _replaceAppUses($contents)
{
$pattern = '#App::uses\\(\\s*[\'"]([a-z0-9_]+)[\'"]\\s*,\\s*[\'"]([a-z0-9/_]+)(?:\\.([a-z0-9/_]+))?[\'"]\\)#i';
$replacement = function ($matches) {
$matches = $this->_mapClassName($matches);
// Chop Lib out as locations moves those files to the top level.
// But only if Lib is not the last folder.
if (isset($matches[3]) && substr($matches[3], 0, 4) === 'Lib/') {
$use = $matches[2] . '\\' . substr($matches[3], 4) . '\\' . $matches[1];
} elseif (count($matches) === 4) {
$use = $matches[2] . '\\' . $matches[3] . '\\' . $matches[1];
} elseif ($matches[2] === 'Vendor') {
$this->out(sprintf('<info>Skip %s as it is a vendor library.</info>', $matches[1]), 1, Shell::VERBOSE);
return $matches[0];
} else {
$use = 'Cake\\' . $matches[2] . '\\' . $matches[1];
if (!class_exists($use) && !interface_exists($use)) {
$use = 'App\\' . substr($use, 5);
}
}
$use = str_replace('/', '\\', $use);
return 'use ' . $use;
};
return preg_replace_callback($pattern, $replacement, $contents, -1, $count);
}