| Conditions | 83 |
| Paths | 147 |
| Total Lines | 398 |
| Code Lines | 305 |
| Lines | 0 |
| Ratio | 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 |
||
| 445 | public function _dispatchActionAndView($action, $repoId, $repositoryName, $user) { |
||
| 446 | $pane = $this->request->get('pane'); |
||
| 447 | switch ($action) { |
||
| 448 | #CREATE REF |
||
| 449 | case 'create': |
||
| 450 | $this->addView('create'); |
||
| 451 | break; |
||
| 452 | #admin |
||
| 453 | case 'view': |
||
| 454 | $this->addAction( 'getRepositoryDetails', array($this->groupId, $repoId) ); |
||
| 455 | $this->addView('view'); |
||
| 456 | break; |
||
| 457 | |||
| 458 | #ADD REF |
||
| 459 | case 'add': |
||
| 460 | $this->addAction('createReference', array($this->groupId, $repositoryName) ); |
||
| 461 | $this->addView('index'); |
||
| 462 | break; |
||
| 463 | #DELETE a repository |
||
| 464 | case 'del': |
||
| 465 | $this->addAction( 'deleteRepository', array($this->groupId, $repoId) ); |
||
| 466 | $this->addView('index'); |
||
| 467 | break; |
||
| 468 | #EDIT |
||
| 469 | case 'edit': |
||
| 470 | $repository = $this->factory->getRepositoryById($repoId); |
||
| 471 | if (empty($repository)) { |
||
| 472 | $this->addError($this->getText('actions_params_error')); |
||
| 473 | $this->redirect('/plugins/git/?action=index&group_id='. $this->groupId); |
||
| 474 | return false; |
||
| 475 | } |
||
| 476 | if ( $this->isAPermittedAction('clone') && $this->request->get('clone') ) { |
||
| 477 | $valid = new Valid_UInt('parent_id'); |
||
| 478 | $valid->required(); |
||
| 479 | if($this->request->valid($valid)) { |
||
| 480 | $parentId = (int)$this->request->get('parent_id'); |
||
| 481 | } |
||
| 482 | $this->addAction( 'cloneRepository', array($this->groupId, $repositoryName, $parentId) ); |
||
| 483 | $this->addAction( 'getRepositoryDetails', array($this->groupId, $parentId) ); |
||
| 484 | $this->addView('view'); |
||
| 485 | } else if ( $this->isAPermittedAction('save') && $this->request->get('save') ) { |
||
| 486 | $repoDesc = null; |
||
| 487 | if ($this->request->exist('repo_desc')) { |
||
| 488 | $repoDesc = GitRepository::DEFAULT_DESCRIPTION; |
||
| 489 | $valid = new Valid_Text('repo_desc'); |
||
| 490 | $valid->required(); |
||
| 491 | if($this->request->valid($valid)) { |
||
| 492 | $repoDesc = $this->request->get('repo_desc'); |
||
| 493 | } |
||
| 494 | } |
||
| 495 | $repoAccess = null; |
||
| 496 | $valid = new Valid_String('repo_access'); |
||
| 497 | $valid->required(); |
||
| 498 | if($this->request->valid($valid) || is_array($this->request->get('repo_access'))) { |
||
| 499 | $repoAccess = $this->request->get('repo_access'); |
||
| 500 | } |
||
| 501 | $this->addAction('save', array($this->groupId, $repoId, $repoAccess, $repoDesc, $pane) ); |
||
| 502 | $this->addView('view'); |
||
| 503 | } else { |
||
| 504 | $this->addError( $this->getText('controller_access_denied') ); |
||
| 505 | $this->redirect('/plugins/git/?group_id='.$this->groupId); |
||
| 506 | } |
||
| 507 | break; |
||
| 508 | #repo_management |
||
| 509 | case 'repo_management': |
||
| 510 | $repository = $this->factory->getRepositoryById($repoId); |
||
| 511 | if (empty($repository)) { |
||
| 512 | $this->addError($this->getText('actions_repo_not_found')); |
||
| 513 | $this->redirect('/plugins/git/?action=index&group_id='. $this->groupId); |
||
| 514 | return false; |
||
| 515 | } |
||
| 516 | $this->addAction('repoManagement', array($repository)); |
||
| 517 | $this->addView('repoManagement'); |
||
| 518 | break; |
||
| 519 | case 'mail': |
||
| 520 | $this->processRepoManagementNotifications($pane, $repoId, $repositoryName, $user); |
||
| 521 | break; |
||
| 522 | #fork |
||
| 523 | case 'fork': |
||
| 524 | $this->addAction('repoManagement', array($this->groupId, $repoId)); |
||
| 525 | $this->addView('forkRepositories'); |
||
| 526 | break; |
||
| 527 | #confirm_private |
||
| 528 | case 'confirm_private': |
||
| 529 | if ( $this->isAPermittedAction('confirm_deletion') && $this->request->get('confirm_deletion') ) { |
||
| 530 | $repository = $this->factory->getRepositoryById($repoId); |
||
| 531 | $this->addAction('confirmDeletion', array($this->groupId, $repository)); |
||
| 532 | $this->addView('confirm_deletion', array( 0=>array('repo_id'=>$repoId) ) ); |
||
| 533 | } |
||
| 534 | else if ( $this->isAPermittedAction('save') && $this->request->get('save') ) { |
||
| 535 | $valid = new Valid_Text('repo_desc'); |
||
| 536 | $valid->required(); |
||
| 537 | if($this->request->valid($valid)) { |
||
| 538 | $repoDesc = $this->request->get('repo_desc'); |
||
| 539 | } |
||
| 540 | $valid = new Valid_String('repo_access'); |
||
| 541 | $valid->required(); |
||
| 542 | if($this->request->valid($valid)) { |
||
| 543 | $repoAccess = $this->request->get('repo_access'); |
||
| 544 | } |
||
| 545 | $this->addAction('confirmPrivate', array($this->groupId, $repoId, $repoAccess, $repoDesc) ); |
||
| 546 | $this->addView('confirmPrivate'); |
||
| 547 | } |
||
| 548 | break; |
||
| 549 | #SET TO PRIVATE |
||
| 550 | case 'set_private': |
||
| 551 | $this->addAction('setPrivate', array($this->groupId, $repoId)); |
||
| 552 | $this->addView('view'); |
||
| 553 | break; |
||
| 554 | case 'fork_repositories': |
||
| 555 | $this->addAction('getProjectRepositoryList', array($this->groupId)); |
||
| 556 | $this->addView('forkRepositories'); |
||
| 557 | break; |
||
| 558 | case 'admin-git-admins': |
||
| 559 | if ($this->request->get('submit')) { |
||
| 560 | $valid = new Valid_Numeric(GitPresenters_AdminGitAdminsPresenter::GIT_ADMIN_SELECTBOX_NAME); |
||
| 561 | $project = $this->projectManager->getProject($this->groupId); |
||
| 562 | |||
| 563 | if ($this->request->validArray($valid)) { |
||
| 564 | $select_project_ids = $this->request->get(GitPresenters_AdminGitAdminsPresenter::GIT_ADMIN_SELECTBOX_NAME); |
||
| 565 | |||
| 566 | if ($select_project_ids) { |
||
| 567 | $this->addAction('updateGitAdminGroups', array($project, $user, $select_project_ids)); |
||
| 568 | } else { |
||
| 569 | $this->addError($this->getText('no_data_retrieved')); |
||
| 570 | } |
||
| 571 | } else { |
||
| 572 | $this->addError($this->getText('not_valid_request')); |
||
| 573 | } |
||
| 574 | } |
||
| 575 | |||
| 576 | $this->addView( |
||
| 577 | 'adminGitAdminsView', |
||
| 578 | array($this->areMirrorsEnabledForProject()) |
||
| 579 | ); |
||
| 580 | |||
| 581 | break; |
||
| 582 | case 'admin': |
||
| 583 | case 'admin-gerrit-templates': |
||
| 584 | $project = $this->projectManager->getProject($this->groupId); |
||
| 585 | |||
| 586 | if ($this->request->get('save')) { |
||
| 587 | $template_content = $this->request->getValidated('git_admin_config_data','text'); |
||
| 588 | if ($this->request->getValidated('git_admin_template_id','uint')) { |
||
| 589 | $template_id = $this->request->get('git_admin_template_id'); |
||
| 590 | $this->addAction('updateTemplate', array($project, $user, $template_content, $template_id)); |
||
| 591 | } else { |
||
| 592 | $template_name = $this->request->getValidated('git_admin_file_name','string'); |
||
| 593 | $this->addAction('createTemplate', array($project, $user, $template_content, $template_name)); |
||
| 594 | } |
||
| 595 | } |
||
| 596 | |||
| 597 | if ($this->request->get('delete')) { |
||
| 598 | if ($this->request->getValidated('git_admin_template_id','uint')) { |
||
| 599 | $template_id = $this->request->get('git_admin_template_id'); |
||
| 600 | $this->addAction('deleteGerritTemplate', array($template_id, $project, $user)); |
||
| 601 | } |
||
| 602 | } |
||
| 603 | |||
| 604 | if ($this->permissions_manager->userIsGitAdmin($user, $project)) { |
||
| 605 | $this->addAction('generateGerritRepositoryAndTemplateList', array($project, $user)); |
||
| 606 | $this->addView( |
||
| 607 | 'adminGerritTemplatesView', |
||
| 608 | array($this->areMirrorsEnabledForProject()) |
||
| 609 | ); |
||
| 610 | } else { |
||
| 611 | $this->addError($this->getText('controller_access_denied')); |
||
| 612 | $this->redirect('/plugins/git/?action=index&group_id='. $this->groupId); |
||
| 613 | return false; |
||
| 614 | } |
||
| 615 | |||
| 616 | break; |
||
| 617 | case 'admin-mass-update': |
||
| 618 | if ($this->request->get('save-mass-change') || $this->request->get('go-to-mass-change')) { |
||
| 619 | $this->checkSynchronizerToken('/plugins/git/?group_id='. (int)$this->groupId .'&action=admin-mass-update'); |
||
| 620 | |||
| 621 | $repositories = $this->getRepositoriesFromIds($this->request->get('repository_ids')); |
||
| 622 | |||
| 623 | if (! $repositories) { |
||
| 624 | $this->addError($this->getText('actions_repo_not_found')); |
||
| 625 | $this->redirect('/plugins/git/?action=index&group_id='. $this->groupId); |
||
| 626 | } |
||
| 627 | } |
||
| 628 | |||
| 629 | if ($this->request->get('go-to-mass-change')) { |
||
| 630 | $this->addAction('setSelectedRepositories', array($repositories)); |
||
| 631 | $this->addView('adminMassUpdateView'); |
||
| 632 | return; |
||
| 633 | } |
||
| 634 | |||
| 635 | if ($this->request->get('save-mass-change')) { |
||
| 636 | $this->addAction('updateMirroring', array( |
||
| 637 | $this->request->getProject(), |
||
| 638 | $repositories, |
||
| 639 | $this->request->get('selected_mirror_ids') |
||
| 640 | )); |
||
| 641 | } |
||
| 642 | |||
| 643 | $this->addView('adminMassUpdateSelectRepositoriesView'); |
||
| 644 | |||
| 645 | break; |
||
| 646 | case 'admin-default-settings': |
||
| 647 | $this->addView( |
||
| 648 | 'adminDefaultSettings', |
||
| 649 | array($this->areMirrorsEnabledForProject()) |
||
| 650 | ); |
||
| 651 | |||
| 652 | break; |
||
| 653 | case 'fetch_git_config': |
||
| 654 | $project = $this->projectManager->getProject($this->groupId); |
||
| 655 | $this->setDefaultPageRendering(false); |
||
| 656 | $this->addAction('fetchGitConfig', array($repoId, $user, $project)); |
||
| 657 | break; |
||
| 658 | case 'fetch_git_template': |
||
| 659 | $project = $this->projectManager->getProject($this->groupId); |
||
| 660 | $template_id = $this->request->getValidated('template_id','uint'); |
||
| 661 | $this->setDefaultPageRendering(false); |
||
| 662 | $this->addAction('fetchGitTemplate', array($template_id, $user, $project)); |
||
| 663 | break; |
||
| 664 | case 'fork_repositories_permissions': |
||
| 665 | $scope = self::SCOPE_PERSONAL; |
||
| 666 | $valid = new Valid_UInt('repos'); |
||
| 667 | $valid->required(); |
||
| 668 | if($this->request->validArray($valid)) { |
||
| 669 | $repos = $this->request->get('repos'); |
||
| 670 | } |
||
| 671 | $valid = new Valid_UInt('to_project'); |
||
| 672 | if ($this->request->valid($valid)) { |
||
| 673 | $toProject = $this->request->get('to_project'); |
||
| 674 | } |
||
| 675 | $valid = new Valid_String('path'); |
||
| 676 | $valid->required(); |
||
| 677 | $path = ''; |
||
| 678 | if($this->request->valid($valid)) { |
||
| 679 | $path = $this->request->get('path'); |
||
| 680 | } |
||
| 681 | $valid = new Valid_String('choose_destination'); |
||
| 682 | $valid->required(); |
||
| 683 | if($this->request->valid($valid)) { |
||
| 684 | $scope = $this->request->get('choose_destination'); |
||
| 685 | } |
||
| 686 | if (!empty($repos)) { |
||
| 687 | $this->addAction('forkRepositoriesPermissions', array($repos, $toProject, $path, $scope)); |
||
| 688 | $this->addView('forkRepositoriesPermissions'); |
||
| 689 | } else { |
||
| 690 | $this->addError($this->getText('actions_params_error')); |
||
| 691 | $this->addAction('getProjectRepositoryList', array($this->groupId)); |
||
| 692 | $this->addView('forkRepositories'); |
||
| 693 | } |
||
| 694 | break; |
||
| 695 | case 'do_fork_repositories': |
||
| 696 | try { |
||
| 697 | if ($this->request->get('choose_destination') == self::SCOPE_PERSONAL) { |
||
| 698 | if ($this->user->isMember($this->groupId)) { |
||
| 699 | $this->_doDispatchForkRepositories($this->request, $user); |
||
| 700 | } else { |
||
| 701 | $this->addError($this->getText('controller_access_denied')); |
||
| 702 | } |
||
| 703 | } else { |
||
| 704 | $this->_doDispatchForkCrossProject($this->request, $user); |
||
| 705 | } |
||
| 706 | } catch (MalformedPathException $e) { |
||
| 707 | $this->addError($this->getText('fork_malformed_path')); |
||
| 708 | } |
||
| 709 | $this->addAction('getProjectRepositoryList', array($this->groupId)); |
||
| 710 | $this->addView('forkRepositories'); |
||
| 711 | break; |
||
| 712 | case "view_last_git_pushes": |
||
| 713 | $vGroupId = new Valid_GroupId(); |
||
| 714 | $vGroupId->required(); |
||
| 715 | if ($this->request->valid($vGroupId)) { |
||
| 716 | $groupId = $this->request->get('group_id'); |
||
| 717 | } |
||
| 718 | $vWeeksNumber = new Valid_UInt('weeks_number'); |
||
| 719 | if ($this->request->valid($vWeeksNumber)) { |
||
| 720 | $weeksNumber = $this->request->get('weeks_number'); |
||
| 721 | } |
||
| 722 | if (empty($weeksNumber) || $weeksNumber > Git_LastPushesGraph::MAX_WEEKSNUMBER) { |
||
| 723 | $weeksNumber = 12; |
||
| 724 | } |
||
| 725 | $imageRenderer = new Git_LastPushesGraph($groupId, $weeksNumber); |
||
| 726 | $imageRenderer->display(); |
||
| 727 | break; |
||
| 728 | case 'migrate_to_gerrit': |
||
| 729 | if (ForgeConfig::get('sys_auth_type') !== ForgeConfig::AUTH_TYPE_LDAP) { |
||
| 730 | $this->redirect('/plugins/git/?group_id='. $this->groupId); |
||
| 731 | break; |
||
| 732 | } |
||
| 733 | |||
| 734 | $repo = $this->factory->getRepositoryById($repoId); |
||
| 735 | $remote_server_id = $this->request->getValidated('remote_server_id', 'uint'); |
||
| 736 | $gerrit_template_id = $this->getValidatedGerritTemplateId($repo); |
||
| 737 | |||
| 738 | if (empty($repo) || empty($remote_server_id) || empty($gerrit_template_id)) { |
||
| 739 | $this->addError($this->getText('actions_params_error')); |
||
| 740 | $this->redirect('/plugins/git/?group_id='. $this->groupId); |
||
| 741 | } else { |
||
| 742 | try { |
||
| 743 | $project_exists = $this->gerritProjectAlreadyExists($remote_server_id, $repo); |
||
| 744 | if ($project_exists) { |
||
| 745 | $this->addError($this->getText('gerrit_project_exists')); |
||
| 746 | } else { |
||
| 747 | $this->addAction('migrateToGerrit', array($repo, $remote_server_id, $gerrit_template_id)); |
||
| 748 | } |
||
| 749 | } catch (Git_Driver_Gerrit_Exception $e) { |
||
| 750 | $this->addError($this->getText('gerrit_server_down')); |
||
| 751 | } |
||
| 752 | $this->addAction('redirectToRepoManagementWithMigrationAccessRightInformation', array($this->groupId, $repoId, $pane)); |
||
| 753 | } |
||
| 754 | break; |
||
| 755 | case 'disconnect_gerrit': |
||
| 756 | $repo = $this->factory->getRepositoryById($repoId); |
||
| 757 | if (empty($repo)) { |
||
| 758 | $this->addError($this->getText('actions_params_error')); |
||
| 759 | $this->redirect('/plugins/git/?group_id='. $this->groupId); |
||
| 760 | } else { |
||
| 761 | $this->addAction('disconnectFromGerrit', array($repo)); |
||
| 762 | $this->addAction('redirectToRepoManagement', array($this->groupId, $repoId, $pane)); |
||
| 763 | } |
||
| 764 | break; |
||
| 765 | case 'delete_gerrit_project': |
||
| 766 | $repo = $this->factory->getRepositoryById($repoId); |
||
| 767 | $server = $this->gerrit_server_factory->getServerById($repo->getRemoteServerId()); |
||
| 768 | $project_gerrit_name = $this->driver_factory->getDriver($server)->getGerritProjectName($repo); |
||
| 769 | |||
| 770 | try { |
||
| 771 | $this->driver_factory->getDriver($server)->deleteProject($server, $project_gerrit_name); |
||
| 772 | } catch (ProjectDeletionException $exception) { |
||
| 773 | $this->addError($this->getText( |
||
| 774 | 'project_deletion_not_possible', |
||
| 775 | array( |
||
| 776 | $project_gerrit_name, |
||
| 777 | $exception->getMessage() |
||
| 778 | ) |
||
| 779 | )); |
||
| 780 | } catch (Git_Driver_Gerrit_Exception $e) { |
||
| 781 | $this->addError($this->getText('gerrit_server_down')); |
||
| 782 | } |
||
| 783 | $migrate_access_right = $this->request->existAndNonEmpty('migrate_access_right'); |
||
| 784 | $this->addAction('redirectToRepoManagementWithMigrationAccessRightInformation', array($this->groupId, $repoId, $pane)); |
||
| 785 | break; |
||
| 786 | |||
| 787 | case 'update_mirroring': |
||
| 788 | $repository = $this->factory->getRepositoryById($repoId); |
||
| 789 | if (! $repository) { |
||
| 790 | $this->addError($this->getText('actions_repo_not_found')); |
||
| 791 | } |
||
| 792 | |||
| 793 | $selected_mirror_ids = $this->request->get('selected_mirror_ids'); |
||
| 794 | |||
| 795 | if (is_array($selected_mirror_ids)) { |
||
| 796 | $this->addAction('updateMirroring', array( |
||
| 797 | $this->request->getProject(), |
||
| 798 | array($repository), |
||
| 799 | $selected_mirror_ids |
||
| 800 | )); |
||
| 801 | } else { |
||
| 802 | $this->addError($this->getText('actions_mirror_ids_not_valid')); |
||
| 803 | } |
||
| 804 | |||
| 805 | $this->addAction('redirectToRepoManagement', array($this->groupId, $repository->getId(), $pane)); |
||
| 806 | break; |
||
| 807 | |||
| 808 | case 'update_default_mirroring': |
||
| 809 | $project = $this->request->getProject(); |
||
| 810 | $selected_mirror_ids = $this->request->get('selected_mirror_ids'); |
||
| 811 | |||
| 812 | if (is_array($selected_mirror_ids)) { |
||
| 813 | $this->addAction('updateDefaultMirroring', array($project, $selected_mirror_ids)); |
||
| 814 | } else { |
||
| 815 | $this->addError($this->getText('actions_mirror_ids_not_valid')); |
||
| 816 | } |
||
| 817 | |||
| 818 | $this->addView( |
||
| 819 | 'adminDefaultSettings', |
||
| 820 | array($this->areMirrorsEnabledForProject()) |
||
| 821 | ); |
||
| 822 | |||
| 823 | break; |
||
| 824 | case 'restore': |
||
| 825 | $this->addAction('restoreRepository', array($repoId, $this->groupId)); |
||
| 826 | break; |
||
| 827 | |||
| 828 | #LIST |
||
| 829 | default: |
||
| 830 | |||
| 831 | $user_id = null; |
||
| 832 | $valid = new Valid_UInt('user'); |
||
| 833 | $valid->required(); |
||
| 834 | if($this->request->valid($valid)) { |
||
| 835 | $user_id = $this->request->get('user'); |
||
| 836 | $this->addData(array('user' => $user_id)); |
||
| 837 | } |
||
| 838 | $this->addAction( 'getProjectRepositoryList', array($this->groupId, $user_id) ); |
||
| 839 | $this->addView('index'); |
||
| 840 | break; |
||
| 841 | } |
||
| 842 | } |
||
| 843 | |||
| 1090 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.