Conditions | 13 |
Paths | 192 |
Total Lines | 55 |
Code Lines | 29 |
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 |
||
81 | public function create(\DateTime $creationDate, $objectId, array $config) |
||
82 | { |
||
83 | /** @var FileAdapterStrategy $adapterStrategy */ |
||
84 | $adapterStrategy = $this->repository->getAdapterStrategy(); |
||
85 | |||
86 | // Build the container path |
||
87 | $hidden = $config[Repository::HIDDEN] ? (rand(1, 5) == 5) : false; |
||
88 | $containerPath = '/'.$this->containerFactory->create($creationDate, $hidden, $objectId, |
||
89 | $config[Repository::TYPE]).'/'; |
||
90 | |||
91 | // Determine the amount of archive revisions to create |
||
92 | $revisions = ($config[Repository::REVISIONS] < 0) ? |
||
93 | rand(1, abs($config[Repository::REVISIONS]) + 1) : (1 + $config[Repository::REVISIONS]); |
||
94 | $draft = intval($config[Repository::DRAFTS] ? (rand(1, 5) == 5) : 0); |
||
95 | $revisionPaths = []; |
||
96 | for ($revision = 1; $revision < $revisions - $draft; ++$revision) { |
||
97 | $revisionPaths[] = $containerPath.$objectId.'-'.$revision.'.'.getenv('OBJECT_RESOURCE_EXTENSION'); |
||
98 | } |
||
99 | if ($revision <= $revisions - $draft) { |
||
100 | $revisionPaths[] = $containerPath.$objectId.'.'.getenv('OBJECT_RESOURCE_EXTENSION'); |
||
101 | } |
||
102 | if ($draft) { |
||
103 | $revisionPaths[] = $containerPath.($draft ? '.' : '').$objectId.'-'.$revisions. |
||
104 | '.'.getenv('OBJECT_RESOURCE_EXTENSION'); |
||
105 | } |
||
106 | |||
107 | // Run through all object paths and create (empty) files |
||
108 | foreach ($revisionPaths as $revisionPathIndex => $revisionPath) { |
||
109 | /** @var RepositoryPathInterface $revRepositoryPath */ |
||
110 | $revRepositoryPath = Kernel::create(RepositoryPath::class, [$this->repository, $revisionPath]); |
||
111 | $absRevisionPath = $adapterStrategy->getAbsoluteResourcePath($revRepositoryPath); |
||
|
|||
112 | |||
113 | // For the first revision |
||
114 | if (!$revisionPathIndex) { |
||
115 | // Create the container directory |
||
116 | $absContainerPath = dirname($absRevisionPath); |
||
117 | |||
118 | // If the resource container cannot be created |
||
119 | if (!is_dir($absContainerPath) && !mkdir($absContainerPath, 0777, true)) { |
||
120 | throw new RuntimeException( |
||
121 | sprintf('Cannot create container directory "%s"', $absContainerPath), |
||
122 | RuntimeException::CANNOT_CREATE_CONTAINER_DIRECTORY |
||
123 | ); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | // If the shallow resource cannot be created |
||
128 | if (!touch($absRevisionPath)) { |
||
129 | throw new RuntimeException( |
||
130 | sprintf('Cannot create shallow resource "%s"', $absRevisionPath), |
||
131 | RuntimeException::CANNOT_CREATE_SHALLOW_RESOURCE |
||
132 | ); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.