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
Pull Request — develop (#322)
by
unknown
01:46
created

Markdown   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 12.96 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 7
loc 54
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 7 38 4

How to fix   Duplicated Code   

Duplicated Code

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:

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;
10
11
use Joomla\Github\AbstractPackage;
12
use Joomla\Http\Exception\UnexpectedResponseException;
13
14
/**
15
 * GitHub API Markdown class.
16
 *
17
 * @documentation http://developer.github.com/v3/markdown
18
 *
19
 * @since  1.0
20
 */
21
class Markdown extends AbstractPackage
22
{
23
	/**
24
	 * Render an arbitrary Markdown document.
25
	 *
26
	 * @param   string  $text     The text object being parsed.
27
	 * @param   string  $mode     The parsing mode; valid options are 'markdown' or 'gfm'.
28
	 * @param   string  $context  An optional repository context, only used in 'gfm' mode.
29
	 *
30
	 * @return  string  Formatted HTML
31
	 *
32
	 * @since   1.0
33
	 * @throws  UnexpectedResponseException
34
	 * @throws  \InvalidArgumentException
35
	 */
36
	public function render($text, $mode = 'gfm', $context = null)
37
	{
38
		// The valid modes
39
		$validModes = array('gfm', 'markdown');
40
41
		// Make sure the scope is valid
42
		if (!in_array($mode, $validModes))
43
		{
44
			throw new \InvalidArgumentException(sprintf('The %s mode is not valid. Valid modes are "gfm" or "markdown".', $mode));
45
		}
46
47
		// Build the request path.
48
		$path = '/markdown';
49
50
		// Build the request data.
51
		$data = str_replace('\\/', '/', json_encode(
52
				array(
53
					'text'    => $text,
54
					'mode'    => $mode,
55
					'context' => $context
56
				)
57
			)
58
		);
59
60
		// Send the request.
61
		$response = $this->client->post($this->fetchUrl($path), $data);
62
63
		// Validate the response code.
64 View Code Duplication
		if ($response->code != 200)
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...
65
		{
66
			// Decode the error response and throw an exception.
67
			$error = json_decode($response->body);
68
			$message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.';
69
			throw new UnexpectedResponseException($response, $message, $response->code);
70
		}
71
72
		return $response->body;
73
	}
74
}
75