/** * Returns a valid root path * * @param ConfigData $config * @return string */ private function validateRootPath(ConfigData $config) { return $config->getProjectRootPath() ?: DirectoryWorker::guessProjectRootPath(); }
/** * Creates and populates a EntityData object with the basic information it needs * * @param string $file * @param ConfigData $config * @return EntityData * @throws MockMakerException */ private function getBasicEntityInformation($file, ConfigData $config) { $obj = new EntityData(); $obj->getFileData()->setFileName(PathWorker::getLastElementInPath($file))->setFileDirectory(PathWorker::getPathUpToName($file) . '/')->setFullFilePath($file); $obj->setClassName(PathWorker::getClassNameFromFilePath($file))->setClassNamespace($this->determineClassNamespace($file, $config->getProjectRootPath()))->setReflectionClass($this->createReflectionClass($obj))->setClassType($this->getClassType($obj->getReflectionClass())); return $obj; }
/** * Generates the mock file's namespace * * If a mockFileBaseNamespace is not defined, this will use composer * to try to find a valid one. Failing that, a wild-assed-guess is returned. * * @param string $mockSavePath Fully qualified file save path of file to be mocked * @param ConfigData $config ConfigData object * Required data points are: * - getMockFileBaseNamespace() * - getProjectRootPath() * - getMockWriteDir() * @return string */ private function generateMockFileNamespace($mockSavePath, ConfigData $config) { $wagNamespace = PathWorker::convertFilePathToClassPath($mockSavePath, $config->getProjectRootPath()); if ($config->getMockFileBaseNamespace()) { return $this->determineWithBaseNamespace($mockSavePath, $config->getMockFileBaseNamespace()); } $composerWorker = new ComposerWorker(); $composerData = $composerWorker->getNamespaceFromComposer($mockSavePath, $config->getProjectRootPath()); if (!$composerData) { return $wagNamespace; } $relNamespacePath = str_replace($composerData['path'], '', $mockSavePath); $namespace = $composerData['namespace'] . str_replace('/', '\\', $relNamespacePath); return rtrim($namespace, '\\'); }