Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like NodeAdminController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use NodeAdminController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 54 | class NodeAdminController extends Controller |
||
| 55 | { |
||
| 56 | /** |
||
| 57 | * @var EntityManager $em |
||
| 58 | */ |
||
| 59 | protected $em; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string $locale |
||
| 63 | */ |
||
| 64 | protected $locale; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var AuthorizationCheckerInterface $authorizationChecker |
||
| 68 | */ |
||
| 69 | protected $authorizationChecker; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var BaseUser $user |
||
| 73 | */ |
||
| 74 | protected $user; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var AclHelper $aclHelper |
||
| 78 | */ |
||
| 79 | protected $aclHelper; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var AclManager |
||
| 83 | */ |
||
| 84 | protected $aclManager; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var NodeAdminPublisher |
||
| 88 | */ |
||
| 89 | protected $nodePublisher; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var TranslatorInterface |
||
| 93 | */ |
||
| 94 | protected $translator; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * init |
||
| 98 | * |
||
| 99 | * @param Request $request |
||
| 100 | */ |
||
| 101 | protected function init(Request $request) |
||
| 102 | { |
||
| 103 | $this->em = $this->getDoctrine()->getManager(); |
||
| 104 | $this->locale = $request->getLocale(); |
||
| 105 | $this->authorizationChecker = $this->container->get('security.authorization_checker'); |
||
| 106 | $this->user = $this->getUser(); |
||
| 107 | $this->aclHelper = $this->container->get('kunstmaan_admin.acl.helper'); |
||
| 108 | $this->aclManager = $this->container->get('kunstmaan_admin.acl.manager'); |
||
| 109 | $this->nodePublisher = $this->container->get('kunstmaan_node.admin_node.publisher'); |
||
| 110 | $this->translator = $this->container->get('translator'); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @Route("/", name="KunstmaanNodeBundle_nodes") |
||
| 115 | * @Template("KunstmaanNodeBundle:Admin:list.html.twig") |
||
| 116 | * |
||
| 117 | * @param Request $request |
||
| 118 | * |
||
| 119 | * @return array |
||
|
|
|||
| 120 | */ |
||
| 121 | public function indexAction(Request $request) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @Route( |
||
| 158 | * "/{id}/copyfromotherlanguage", |
||
| 159 | * requirements={"id" = "\d+"}, |
||
| 160 | * name="KunstmaanNodeBundle_nodes_copyfromotherlanguage" |
||
| 161 | * ) |
||
| 162 | * @Method("GET") |
||
| 163 | * |
||
| 164 | * @param Request $request |
||
| 165 | * @param int $id The node id |
||
| 166 | * |
||
| 167 | * @return RedirectResponse |
||
| 168 | * @throws AccessDeniedException |
||
| 169 | */ |
||
| 170 | public function copyFromOtherLanguageAction(Request $request, $id) |
||
| 171 | { |
||
| 172 | $this->init($request); |
||
| 173 | /* @var Node $node */ |
||
| 174 | $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); |
||
| 175 | |||
| 176 | $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node); |
||
| 177 | |||
| 178 | $originalLanguage = $request->get('originallanguage'); |
||
| 179 | $otherLanguageNodeTranslation = $node->getNodeTranslation($originalLanguage, true); |
||
| 180 | $otherLanguageNodeNodeVersion = $otherLanguageNodeTranslation->getPublicNodeVersion(); |
||
| 181 | $otherLanguagePage = $otherLanguageNodeNodeVersion->getRef($this->em); |
||
| 182 | $myLanguagePage = $this->get('kunstmaan_admin.clone.helper') |
||
| 183 | ->deepCloneAndSave($otherLanguagePage); |
||
| 184 | |||
| 185 | /* @var NodeTranslation $nodeTranslation */ |
||
| 186 | $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation') |
||
| 187 | ->createNodeTranslationFor($myLanguagePage, $this->locale, $node, $this->user); |
||
| 188 | $nodeVersion = $nodeTranslation->getPublicNodeVersion(); |
||
| 189 | |||
| 190 | $this->get('event_dispatcher')->dispatch( |
||
| 191 | Events::COPY_PAGE_TRANSLATION, |
||
| 192 | new CopyPageTranslationNodeEvent( |
||
| 193 | $node, |
||
| 194 | $nodeTranslation, |
||
| 195 | $nodeVersion, |
||
| 196 | $myLanguagePage, |
||
| 197 | $otherLanguageNodeTranslation, |
||
| 198 | $otherLanguageNodeNodeVersion, |
||
| 199 | $otherLanguagePage, |
||
| 200 | $originalLanguage |
||
| 201 | ) |
||
| 202 | ); |
||
| 203 | |||
| 204 | return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id))); |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @Route( |
||
| 209 | * "/{id}/recopyfromotherlanguage", |
||
| 210 | * requirements={"id" = "\d+"}, |
||
| 211 | * name="KunstmaanNodeBundle_nodes_recopyfromotherlanguage" |
||
| 212 | * ) |
||
| 213 | * @Method("POST") |
||
| 214 | * |
||
| 215 | * @param Request $request |
||
| 216 | * @param int $id The node id |
||
| 217 | * |
||
| 218 | * @return RedirectResponse |
||
| 219 | * @throws AccessDeniedException |
||
| 220 | */ |
||
| 221 | public function recopyFromOtherLanguageAction(Request $request, $id) |
||
| 222 | { |
||
| 223 | $this->init($request); |
||
| 224 | /* @var Node $node */ |
||
| 225 | $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); |
||
| 226 | |||
| 227 | $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node); |
||
| 228 | |||
| 229 | $otherLanguageNodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($request->get('source')); |
||
| 230 | $otherLanguageNodeNodeVersion = $otherLanguageNodeTranslation->getPublicNodeVersion(); |
||
| 231 | $otherLanguagePage = $otherLanguageNodeNodeVersion->getRef($this->em); |
||
| 232 | $myLanguagePage = $this->get('kunstmaan_admin.clone.helper') |
||
| 233 | ->deepCloneAndSave($otherLanguagePage); |
||
| 234 | |||
| 235 | /* @var NodeTranslation $nodeTranslation */ |
||
| 236 | $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation') |
||
| 237 | ->addDraftNodeVersionFor($myLanguagePage, $this->locale, $node, $this->user); |
||
| 238 | $nodeVersion = $nodeTranslation->getPublicNodeVersion(); |
||
| 239 | |||
| 240 | $this->get('event_dispatcher')->dispatch( |
||
| 241 | Events::RECOPY_PAGE_TRANSLATION, |
||
| 242 | new RecopyPageTranslationNodeEvent( |
||
| 243 | $node, |
||
| 244 | $nodeTranslation, |
||
| 245 | $nodeVersion, |
||
| 246 | $myLanguagePage, |
||
| 247 | $otherLanguageNodeTranslation, |
||
| 248 | $otherLanguageNodeNodeVersion, |
||
| 249 | $otherLanguagePage, |
||
| 250 | $otherLanguageNodeTranslation->getLang() |
||
| 251 | ) |
||
| 252 | ); |
||
| 253 | |||
| 254 | return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id, 'subaction' => NodeVersion::DRAFT_VERSION))); |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @Route( |
||
| 259 | * "/{id}/createemptypage", |
||
| 260 | * requirements={"id" = "\d+"}, |
||
| 261 | * name="KunstmaanNodeBundle_nodes_createemptypage" |
||
| 262 | * ) |
||
| 263 | * @Method("GET") |
||
| 264 | * |
||
| 265 | * @param Request $request |
||
| 266 | * @param int $id |
||
| 267 | * |
||
| 268 | * @return RedirectResponse |
||
| 269 | * @throws AccessDeniedException |
||
| 270 | */ |
||
| 271 | public function createEmptyPageAction(Request $request, $id) |
||
| 272 | { |
||
| 273 | $this->init($request); |
||
| 274 | /* @var Node $node */ |
||
| 275 | $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); |
||
| 276 | |||
| 277 | $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node); |
||
| 278 | |||
| 279 | $entityName = $node->getRefEntityName(); |
||
| 280 | /* @var HasNodeInterface $myLanguagePage */ |
||
| 281 | $myLanguagePage = new $entityName(); |
||
| 282 | $myLanguagePage->setTitle('New page'); |
||
| 283 | |||
| 284 | $this->em->persist($myLanguagePage); |
||
| 285 | $this->em->flush(); |
||
| 286 | /* @var NodeTranslation $nodeTranslation */ |
||
| 287 | $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation') |
||
| 288 | ->createNodeTranslationFor($myLanguagePage, $this->locale, $node, $this->user); |
||
| 289 | $nodeVersion = $nodeTranslation->getPublicNodeVersion(); |
||
| 290 | |||
| 291 | $this->get('event_dispatcher')->dispatch( |
||
| 292 | Events::ADD_EMPTY_PAGE_TRANSLATION, |
||
| 293 | new NodeEvent($node, $nodeTranslation, $nodeVersion, $myLanguagePage) |
||
| 294 | ); |
||
| 295 | |||
| 296 | return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id))); |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @Route("/{id}/publish", requirements={"id" = |
||
| 301 | * "\d+"}, |
||
| 302 | * name="KunstmaanNodeBundle_nodes_publish") |
||
| 303 | * @Method({"GET", "POST"}) |
||
| 304 | * |
||
| 305 | * @param Request $request |
||
| 306 | * @param int $id |
||
| 307 | * |
||
| 308 | * @return RedirectResponse |
||
| 309 | * @throws AccessDeniedException |
||
| 310 | */ |
||
| 311 | View Code Duplication | public function publishAction(Request $request, $id) |
|
| 312 | { |
||
| 313 | $this->init($request); |
||
| 314 | /* @var Node $node */ |
||
| 315 | $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); |
||
| 316 | |||
| 317 | $nodeTranslation = $node->getNodeTranslation($this->locale, true); |
||
| 318 | $request = $this->get('request_stack')->getCurrentRequest(); |
||
| 319 | $this->nodePublisher->chooseHowToPublish($request, $nodeTranslation, $this->translator); |
||
| 320 | |||
| 321 | return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $node->getId()))); |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @Route( |
||
| 326 | * "/{id}/unpublish", |
||
| 327 | * requirements={"id" = "\d+"}, |
||
| 328 | * name="KunstmaanNodeBundle_nodes_unpublish" |
||
| 329 | * ) |
||
| 330 | * @Method({"GET", "POST"}) |
||
| 331 | * |
||
| 332 | * @param Request $request |
||
| 333 | * @param int $id |
||
| 334 | * |
||
| 335 | * @return RedirectResponse |
||
| 336 | * @throws AccessDeniedException |
||
| 337 | */ |
||
| 338 | View Code Duplication | public function unPublishAction(Request $request, $id) |
|
| 339 | { |
||
| 340 | $this->init($request); |
||
| 341 | /* @var Node $node */ |
||
| 342 | $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); |
||
| 343 | |||
| 344 | $nodeTranslation = $node->getNodeTranslation($this->locale, true); |
||
| 345 | $request = $this->get('request_stack')->getCurrentRequest(); |
||
| 346 | $this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator); |
||
| 347 | |||
| 348 | return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $node->getId()))); |
||
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @Route( |
||
| 353 | * "/{id}/unschedulepublish", |
||
| 354 | * requirements={"id" = "\d+"}, |
||
| 355 | * name="KunstmaanNodeBundle_nodes_unschedule_publish" |
||
| 356 | * ) |
||
| 357 | * @Method({"GET", "POST"}) |
||
| 358 | * |
||
| 359 | * @param Request $request |
||
| 360 | * @param int $id |
||
| 361 | * |
||
| 362 | * @return RedirectResponse |
||
| 363 | * @throws AccessDeniedException |
||
| 364 | */ |
||
| 365 | View Code Duplication | public function unSchedulePublishAction(Request $request, $id) |
|
| 366 | { |
||
| 367 | $this->init($request); |
||
| 368 | |||
| 369 | /* @var Node $node */ |
||
| 370 | $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); |
||
| 371 | |||
| 372 | $nodeTranslation = $node->getNodeTranslation($this->locale, true); |
||
| 373 | $this->nodePublisher->unSchedulePublish($nodeTranslation); |
||
| 374 | |||
| 375 | $this->addFlash( |
||
| 376 | FlashTypes::SUCCESS, |
||
| 377 | $this->get('translator')->trans('kuma_node.admin.unschedule.flash.success') |
||
| 378 | ); |
||
| 379 | |||
| 380 | return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id))); |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @Route( |
||
| 385 | * "/{id}/delete", |
||
| 386 | * requirements={"id" = "\d+"}, |
||
| 387 | * name="KunstmaanNodeBundle_nodes_delete" |
||
| 388 | * ) |
||
| 389 | * @Method("POST") |
||
| 390 | * |
||
| 391 | * @param Request $request |
||
| 392 | * @param int $id |
||
| 393 | * |
||
| 394 | * @return RedirectResponse |
||
| 395 | * @throws AccessDeniedException |
||
| 396 | */ |
||
| 397 | public function deleteAction(Request $request, $id) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @Route( |
||
| 449 | * "/{id}/duplicate", |
||
| 450 | * requirements={"id" = "\d+"}, |
||
| 451 | * name="KunstmaanNodeBundle_nodes_duplicate" |
||
| 452 | * ) |
||
| 453 | * @Method("POST") |
||
| 454 | * |
||
| 455 | * @param Request $request |
||
| 456 | * @param int $id |
||
| 457 | * |
||
| 458 | * @return RedirectResponse |
||
| 459 | * @throws AccessDeniedException |
||
| 460 | */ |
||
| 461 | public function duplicateAction(Request $request, $id) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * @Route( |
||
| 521 | * "/{id}/revert", |
||
| 522 | * requirements={"id" = "\d+"}, |
||
| 523 | * defaults={"subaction" = "public"}, |
||
| 524 | * name="KunstmaanNodeBundle_nodes_revert" |
||
| 525 | * ) |
||
| 526 | * @Method("GET") |
||
| 527 | * |
||
| 528 | * @param Request $request |
||
| 529 | * @param int $id The node id |
||
| 530 | * |
||
| 531 | * @return RedirectResponse |
||
| 532 | * @throws AccessDeniedException |
||
| 533 | * @throws InvalidArgumentException |
||
| 534 | */ |
||
| 535 | public function revertAction(Request $request, $id) |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @Route( |
||
| 606 | * "/{id}/add", |
||
| 607 | * requirements={"id" = "\d+"}, |
||
| 608 | * name="KunstmaanNodeBundle_nodes_add" |
||
| 609 | * ) |
||
| 610 | * @Method("POST") |
||
| 611 | * |
||
| 612 | * @param Request $request |
||
| 613 | * @param int $id |
||
| 614 | * |
||
| 615 | * @return RedirectResponse |
||
| 616 | * @throws AccessDeniedException |
||
| 617 | * @throws InvalidArgumentException |
||
| 618 | */ |
||
| 619 | public function addAction(Request $request, $id) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * @Route("/add-homepage", name="KunstmaanNodeBundle_nodes_add_homepage") |
||
| 675 | * @Method("POST") |
||
| 676 | * |
||
| 677 | * @return RedirectResponse |
||
| 678 | * @throws AccessDeniedException |
||
| 679 | * @throws InvalidArgumentException |
||
| 680 | */ |
||
| 681 | public function addHomepageAction(Request $request) |
||
| 682 | { |
||
| 683 | $this->init($request); |
||
| 684 | |||
| 685 | // Check with Acl |
||
| 686 | $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN'); |
||
| 687 | |||
| 688 | $type = $this->validatePageType($request); |
||
| 689 | |||
| 690 | $newPage = $this->createNewPage($request, $type); |
||
| 691 | |||
| 692 | /* @var Node $nodeNewPage */ |
||
| 693 | $nodeNewPage = $this->em->getRepository('KunstmaanNodeBundle:Node') |
||
| 694 | ->createNodeFor($newPage, $this->locale, $this->user); |
||
| 695 | $nodeTranslation = $nodeNewPage->getNodeTranslation( |
||
| 696 | $this->locale, |
||
| 697 | true |
||
| 698 | ); |
||
| 699 | $this->em->flush(); |
||
| 700 | |||
| 701 | // Set default permissions |
||
| 702 | $this->container->get('kunstmaan_node.acl_permission_creator_service') |
||
| 703 | ->createPermission($nodeNewPage); |
||
| 704 | |||
| 705 | $nodeVersion = $nodeTranslation->getPublicNodeVersion(); |
||
| 706 | |||
| 707 | $this->get('event_dispatcher')->dispatch( |
||
| 708 | Events::ADD_NODE, |
||
| 709 | new NodeEvent( |
||
| 710 | $nodeNewPage, $nodeTranslation, $nodeVersion, $newPage |
||
| 711 | ) |
||
| 712 | ); |
||
| 713 | |||
| 714 | return $this->redirect( |
||
| 715 | $this->generateUrl( |
||
| 716 | 'KunstmaanNodeBundle_nodes_edit', |
||
| 717 | array('id' => $nodeNewPage->getId()) |
||
| 718 | ) |
||
| 719 | ); |
||
| 720 | } |
||
| 721 | |||
| 722 | /** |
||
| 723 | * @Route("/reorder", name="KunstmaanNodeBundle_nodes_reorder") |
||
| 724 | * @Method("POST") |
||
| 725 | * |
||
| 726 | * @param Request $request |
||
| 727 | * |
||
| 728 | * @return string |
||
| 729 | * @throws AccessDeniedException |
||
| 730 | */ |
||
| 731 | public function reorderAction(Request $request) |
||
| 789 | |||
| 790 | /** |
||
| 791 | * @Route( |
||
| 792 | * "/{id}/{subaction}", |
||
| 793 | * requirements={"id" = "\d+"}, |
||
| 794 | * defaults={"subaction" = "public"}, |
||
| 795 | * name="KunstmaanNodeBundle_nodes_edit" |
||
| 796 | * ) |
||
| 797 | * @Template("@KunstmaanNode/NodeAdmin/edit.html.twig") |
||
| 798 | * @Method({"GET", "POST"}) |
||
| 799 | * |
||
| 800 | * @param Request $request |
||
| 801 | * @param int $id The node id |
||
| 802 | * @param string $subaction The subaction (draft|public) |
||
| 803 | * |
||
| 804 | * @return RedirectResponse|array |
||
| 805 | * @throws AccessDeniedException |
||
| 806 | */ |
||
| 807 | public function editAction(Request $request, $id, $subaction) |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * @Route( |
||
| 1016 | * "checkNodeVersionLock/{id}/{public}", |
||
| 1017 | * requirements={"id" = "\d+", "public" = "(0|1)"}, |
||
| 1018 | * name="KunstmaanNodeBundle_nodes_versionlock_check" |
||
| 1019 | * ) |
||
| 1020 | * @param Request $request |
||
| 1021 | * @param $id |
||
| 1022 | * @return JsonResponse |
||
| 1023 | */ |
||
| 1024 | public function checkNodeVersionLockAction(Request $request, $id, $public) |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * @param NodeTranslation $nodeTranslation |
||
| 1056 | * @param bool $isPublic |
||
| 1057 | * @return bool |
||
| 1058 | */ |
||
| 1059 | private function isNodeVersionLocked(NodeTranslation $nodeTranslation, $isPublic) |
||
| 1069 | |||
| 1070 | /** |
||
| 1071 | * @param HasNodeInterface $page The page |
||
| 1072 | * @param NodeTranslation $nodeTranslation The node translation |
||
| 1073 | * @param NodeVersion $nodeVersion The node version |
||
| 1074 | * |
||
| 1075 | * @return NodeVersion |
||
| 1076 | */ |
||
| 1077 | private function createDraftVersion( |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * @param Node $node The node |
||
| 1122 | * @param string $permission The permission to check for |
||
| 1123 | * |
||
| 1124 | * @throws AccessDeniedException |
||
| 1125 | */ |
||
| 1126 | private function checkPermission(Node $node, $permission) |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * @param EntityManager $em The Entity Manager |
||
| 1135 | * @param BaseUser $user The user who deletes the children |
||
| 1136 | * @param string $locale The locale that was used |
||
| 1137 | * @param ArrayCollection $children The children array |
||
| 1138 | */ |
||
| 1139 | private function deleteNodeChildren( |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * @param Request $request |
||
| 1186 | * @param string $type |
||
| 1187 | * |
||
| 1188 | * @return HasNodeInterface |
||
| 1189 | */ |
||
| 1190 | private function createNewPage(Request $request, $type) |
||
| 1191 | { |
||
| 1192 | /* @var HasNodeInterface $newPage */ |
||
| 1193 | $newPage = new $type(); |
||
| 1194 | |||
| 1195 | $title = $request->get('title'); |
||
| 1196 | if (is_string($title) && !empty($title)) { |
||
| 1197 | $newPage->setTitle($title); |
||
| 1198 | } else { |
||
| 1199 | $newPage->setTitle($this->get('translator')->trans('kuma_node.admin.new_page.title.default')); |
||
| 1200 | } |
||
| 1201 | $this->em->persist($newPage); |
||
| 1202 | $this->em->flush(); |
||
| 1203 | |||
| 1204 | return $newPage; |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * @param Request $request |
||
| 1209 | * |
||
| 1210 | * @return string |
||
| 1211 | * @throw InvalidArgumentException |
||
| 1212 | */ |
||
| 1213 | private function validatePageType($request) |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * @param Node $node |
||
| 1228 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 1229 | */ |
||
| 1230 | private function renderNodeNotTranslatedPage(Node $node) |
||
| 1268 | } |
||
| 1269 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.