Showing 117 of 117 total issues
Method act
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public Response act(final Request req) throws IOException {
if (this.count <= 0) {
throw new IllegalArgumentException(
Method next
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static State next(final InputStream stream, final State state,
final ByteArrayOutputStream line) throws IOException {
final int next = stream.read();
if (next == -1) {
throw new IOException("chunked stream ended unexpectedly");
Method header
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public List<String> header(final CharSequence key)
throws IOException {
final List<String> values = this.map().getOrDefault(
new UncheckedText(
Method header
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public List<String> header(final CharSequence key)
throws IOException {
final List<String> values = this.map().getOrDefault(
new UncheckedText(
Method chunkSize
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int chunkSize(final InputStream stream)
throws IOException {
final ByteArrayOutputStream baos = ChunkedInputStream.sizeLine(stream);
final String data = baos.toString(Charset.defaultCharset().name());
final int separator = data.indexOf(';');
Method urn
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private Opt<String> urn(final String user, final String pwd) {
final String urn;
try {
urn = this.usernames.get(
String.format(
Method asMap
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private static SortedMap<String, List<String>> asMap(final String query) {
final SortedMap<String, List<String>> params = new TreeMap<>();
if (query != null) {
for (final String pair : query.split("&")) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parse
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private static Request parse(final InputStream input) throws IOException {
boolean eof = true;
final Collection<String> head = new LinkedList<>();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parse
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private static Request parse(final InputStream input) throws IOException {
boolean eof = true;
final Collection<String> head = new LinkedList<>();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Method response
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private Response response(final String home, final URI dest,
final com.jcabi.http.Response rsp) {
final Collection<String> hdrs = new LinkedList<>();
hdrs.add(
String.format(
Method prepareDocType
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static void prepareDocType(final InputStream body,
final Transformer transformer) throws IOException {
try {
final String html = "html";
final DocumentType doctype = RsPrettyXml.getDocType(body);
Method printHead
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public void printHead(final OutputStream output) throws IOException {
final String eol = "\r\n";
final Writer writer =
new OutputStreamWriter(output, StandardCharsets.UTF_8);
int pos = 0;
Method route
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public Opt<Response> route(final Request req) throws IOException {
final Iterator<String> headers =
new RqHeaders.Base(req).header("Accept-Encoding").iterator();
final Opt<Response> resp;
Method enter
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public Opt<Identity> enter(final Request trequest)
throws IOException {
final Href href = new RqHref.Base(trequest).href();
final Iterator<String> code = href.param(PsFacebook.CODE).iterator();
Method cookie
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public Iterable<String> cookie(final CharSequence key)
throws IOException {
final Map<String, String> map = this.map();
final String value = map.getOrDefault(
Method equals
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
@SuppressFBWarnings("EQ_UNUSUAL")
public boolean equals(final Object that) {
return new Unchecked<>(
new Or(
Method equals
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
@SuppressFBWarnings("EQ_UNUSUAL")
public boolean equals(final Object that) {
return new Unchecked<>(
new Or(
Method request
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private com.jcabi.http.Request request(final Request req,
final URI dest) throws Exception {
final String method = new RqMethod.Base(req).method();
com.jcabi.http.Request proxied = new JdkRequest(dest).method(method);
Method freshMap
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private Map<String, List<String>> freshMap() throws IOException {
final String body = new RqPrint(this.req).printBody();
final Map<String, List<String>> map = new HashMap<>(1);
for (final String pair : body.split("&")) {
if (pair.isEmpty()) {
Similar blocks of code found in 2 locations. Consider refactoring. Open
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private static MediaTypes getType(final Request req) throws IOException {
MediaTypes list = new MediaTypes();
final Iterable<String> headers = new RqHeaders.Base(req)
.header("Content-Type");
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 72.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76