| Conditions | 3 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 63 | public function createFromApplication(Application $application, UserInterface $user) |
||
| 64 | { |
||
| 65 | $repository = $this->cvRepo; |
||
| 66 | $cv = $repository->create(); |
||
|
|
|||
| 67 | $cv->setContact($application->getContact()); |
||
| 68 | |||
| 69 | $assignedUser = $application->getJob()->getUser(); |
||
| 70 | $cv->setUser($assignedUser); |
||
| 71 | |||
| 72 | $perms = $cv->getPermissions(); |
||
| 73 | |||
| 74 | $perms->inherit($application->getPermissions()); |
||
| 75 | // grant view permission to the user that issued this creation. |
||
| 76 | $perms->grant($user, PermissionsInterface::PERMISSION_VIEW); |
||
| 77 | // revoke change permission to the original applicant |
||
| 78 | $perms->revoke($application->getUser(), PermissionsInterface::PERMISSION_CHANGE); |
||
| 79 | |||
| 80 | $applicationAttachments = $application->getAttachments(); |
||
| 81 | |||
| 82 | if (count($applicationAttachments) > 0) { |
||
| 83 | $cvAttachments = []; |
||
| 84 | $fileManager = $this->fileManager; |
||
| 85 | |||
| 86 | foreach ($applicationAttachments as $from) { |
||
| 87 | //$gridfs = new \MongoGridFS($this->dm->getClient()); |
||
| 88 | //$file = new \MongoGridFSFile($gridfs, $appAttachment->getFile()); |
||
| 89 | |||
| 90 | /* |
||
| 91 | $cvAttachment = new CvAttachment(); |
||
| 92 | $cvAttachment->setName($applicationAttachment->getName()); |
||
| 93 | $cvAttachment->setType($applicationAttachment->getType()); |
||
| 94 | $cvAttachment->setUser($assignedUser); |
||
| 95 | $cvAttachment->setFile($file); |
||
| 96 | $cvAttachment->setDateUploaded($applicationAttachment->getDateUploaded()); |
||
| 97 | */ |
||
| 98 | $fromMetadata = $from->getMetadata(); |
||
| 99 | $metadata = new FileMetadata(); |
||
| 100 | $metadata->setContentType($fromMetadata->getContentType()); |
||
| 101 | $metadata->setUser($assignedUser); |
||
| 102 | |||
| 103 | $fromStream = $fileManager->getStream($from); |
||
| 104 | $toAttachment = $fileManager->uploadFromStream( |
||
| 105 | Attachment::class, |
||
| 106 | $metadata, |
||
| 107 | $from->getName(), |
||
| 108 | $fromStream |
||
| 109 | ); |
||
| 110 | $cvAttachments[] = $toAttachment; |
||
| 111 | } |
||
| 112 | |||
| 113 | $cv->setAttachments(new ArrayCollection($cvAttachments)); |
||
| 114 | } |
||
| 115 | |||
| 116 | return $cv; |
||
| 117 | } |
||
| 192 | } |