GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( b5e3c2...7799bc )
by
unknown
15s
created

Merging::perform()   B

Complexity

Conditions 8
Paths 14

Size

Total Lines 53
Code Lines 28

Duplication

Lines 16
Ratio 30.19 %

Importance

Changes 0
Metric Value
cc 8
eloc 28
nc 14
nop 5
dl 16
loc 53
rs 7.1199
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * Part of the Joomla Framework GitHub Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE
7
 */
8
9
namespace Joomla\Github\Package\Repositories;
10
11
use Joomla\Github\AbstractPackage;
12
13
/**
14
 * GitHub API Repositories Merging class for the Joomla Framework.
15
 *
16
 * @documentation http://developer.github.com/v3/repos/merging
17
 *
18
 * @since  1.0
19
 */
20
class Merging extends AbstractPackage
21
{
22
	/**
23
	 * Perform a merge.
24
	 *
25
	 * @param   string  $owner           The name of the owner of the GitHub repository.
26
	 * @param   string  $repo            The name of the GitHub repository.
27
	 * @param   string  $base            The name of the base branch that the head will be merged into.
28
	 * @param   string  $head            The head to merge. This can be a branch name or a commit SHA1.
29
	 * @param   string  $commit_message  Commit message to use for the merge commit.
30
	 *                                   If omitted, a default message will be used.
31
	 *
32
	 * @throws \UnexpectedValueException
33
	 * @since   1.0
34
	 *
35
	 * @return  boolean
36
	 */
37
	public function perform($owner, $repo, $base, $head, $commit_message = '')
38
	{
39
		// Build the request path.
40
		$path = '/repos/' . $owner . '/' . $repo . '/merges';
41
42
		$data = new \stdClass;
43
44
		$data->base = $base;
45
		$data->head = $head;
46
47
		if ($commit_message)
48
		{
49
			$data->commit_message = $commit_message;
50
		}
51
52
		// Send the request.
53
		$response = $this->client->post($this->fetchUrl($path), json_encode($data));
54
55
		switch ($response->code)
56
		{
57
			case '201':
58
				// Success
59
				return json_decode($response->body);
60
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
61
62
			case '204':
63
				// No-op response (base already contains the head, nothing to merge)
64
				throw new \UnexpectedValueException('Nothing to merge');
65
				break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
66
67 View Code Duplication
			case '404':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
				// Missing base or Missing head response
69
				$error = json_decode($response->body);
70
71
				$message = (isset($error->message)) ? $error->message : 'Missing base or head: ' . $response->code;
72
73
				throw new \UnexpectedValueException($message);
74
				break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
75
76 View Code Duplication
			case '409':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
				// Merge conflict response
78
				$error = json_decode($response->body);
79
80
				$message = (isset($error->message)) ? $error->message : 'Merge conflict ' . $response->code;
81
82
				throw new \UnexpectedValueException($message);
83
				break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
84
85
			default :
86
				throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
87
				break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
88
		}
89
	}
90
}
91