Conditions | 8 |
Paths | 20 |
Total Lines | 75 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
65 | protected function initBundleDirectoryStructure(InputInterface $input, OutputInterface $output) |
||
66 | { |
||
67 | // Bootstrap SS so we can use module listing |
||
68 | $frameworkPath = $this->container->getParameter('behat.silverstripe_extension.framework_path'); |
||
69 | $_GET['flush'] = 1; |
||
70 | require_once $frameworkPath . '/core/Core.php'; |
||
71 | unset($_GET['flush']); |
||
72 | |||
73 | $featuresPath = $input->getArgument('features'); |
||
74 | if (!$featuresPath) { |
||
75 | throw new \InvalidArgumentException('Please specify a module name (e.g. "@mymodule")'); |
||
76 | } |
||
77 | |||
78 | // Can't use 'behat.paths.base' since that's locked at this point to base folder (not module) |
||
79 | $pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix'); |
||
80 | $currentModuleName = null; |
||
81 | $modules = \SS_ClassLoader::instance()->getManifest()->getModules(); |
||
82 | $currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module'); |
||
83 | |||
84 | // get module from short notation if path starts from @ |
||
85 | if (preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) { |
||
86 | $currentModuleName = $matches[1]; |
||
87 | // TODO Replace with proper module loader once AJShort's changes are merged into core |
||
88 | if (!array_key_exists($currentModuleName, $modules)) { |
||
89 | throw new \InvalidArgumentException(sprintf('Module "%s" not found', $currentModuleName)); |
||
90 | } |
||
91 | $currentModulePath = $modules[$currentModuleName]; |
||
92 | } |
||
93 | |||
94 | if (!$currentModuleName) { |
||
95 | throw new \InvalidArgumentException('Can not find module to initialize suite.'); |
||
96 | } |
||
97 | |||
98 | // TODO Retrieve from module definition once that's implemented |
||
99 | if ($input->getOption('namespace')) { |
||
100 | $namespace = $input->getOption('namespace'); |
||
101 | } else { |
||
102 | $namespace = ucfirst($currentModuleName); |
||
103 | } |
||
104 | $namespace .= '\\' . $this->container->getParameter('behat.silverstripe_extension.context.namespace_suffix'); |
||
105 | |||
106 | $featuresPath = rtrim($currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix, DIRECTORY_SEPARATOR); |
||
107 | $basePath = $this->container->getParameter('behat.paths.base').DIRECTORY_SEPARATOR; |
||
108 | $bootstrapPath = $featuresPath.DIRECTORY_SEPARATOR.'bootstrap'; |
||
109 | $contextPath = $bootstrapPath.DIRECTORY_SEPARATOR.'Context'; |
||
110 | |||
111 | if (!is_dir($featuresPath)) { |
||
112 | mkdir($featuresPath, 0777, true); |
||
113 | mkdir($bootstrapPath, 0777, true); |
||
114 | // touch($bootstrapPath.DIRECTORY_SEPARATOR.'_manifest_exclude'); |
||
115 | $output->writeln( |
||
116 | '<info>+d</info> ' . |
||
117 | str_replace($basePath, '', realpath($featuresPath)) . |
||
118 | ' <comment>- place your *.feature files here</comment>' |
||
119 | ); |
||
120 | } |
||
121 | |||
122 | if (!is_dir($contextPath)) { |
||
123 | mkdir($contextPath, 0777, true); |
||
124 | |||
125 | $className = $this->container->getParameter('behat.context.class'); |
||
126 | file_put_contents( |
||
127 | $contextPath . DIRECTORY_SEPARATOR . $className . '.php', |
||
128 | strtr($this->getFeatureContextSkelet(), array( |
||
129 | '%NAMESPACE%' => $namespace |
||
130 | )) |
||
131 | ); |
||
132 | |||
133 | $output->writeln( |
||
134 | '<info>+f</info> ' . |
||
135 | str_replace($basePath, '', realpath($contextPath)) . DIRECTORY_SEPARATOR . |
||
136 | 'FeatureContext.php <comment>- place your feature related code here</comment>' |
||
137 | ); |
||
138 | } |
||
139 | } |
||
140 | |||
249 |