package de.retest.recheck.review.workers;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import de.retest.recheck.ignore.JSShouldIgnoreImpl;
import de.retest.recheck.ignore.RecheckIgnoreUtil;
import de.retest.recheck.ignore.ShouldIgnore;
import de.retest.recheck.review.GlobalIgnoreApplier;
import de.retest.recheck.review.GlobalIgnoreApplier.PersistableGlobalIgnoreApplier;
import de.retest.recheck.review.counter.Counter;
import de.retest.recheck.review.ignore.io.Loaders;

public class LoadShouldIgnoreWorker {

	private final Counter counter;
	private final Consumer<GlobalIgnoreApplier> applier;

	public LoadShouldIgnoreWorker( final Counter counter, final Consumer<GlobalIgnoreApplier> applier ) {
		this.counter = counter;
		this.applier = applier;
	}

	public GlobalIgnoreApplier load() throws IOException {
		final Optional<Path> path = RecheckIgnoreUtil.getIgnoreFile();
		final PersistableGlobalIgnoreApplier ignoreApplier = Loaders
				.load( Files.lines(
						path.orElseThrow( () -> new IllegalArgumentException( "No reliable argument found." ) ) ) ) //
				.filter( ShouldIgnore.class::isInstance ) //
				.map( ShouldIgnore.class::cast ) //
				.collect( Collectors.collectingAndThen( Collectors.toList(), PersistableGlobalIgnoreApplier::new ) );
		final GlobalIgnoreApplier result = GlobalIgnoreApplier.create( counter, ignoreApplier );
		if ( RecheckIgnoreUtil.getIgnoreRuleFile().isPresent() ) {
			result.add( new JSShouldIgnoreImpl( RecheckIgnoreUtil.getIgnoreRuleFile().get() ) );
		}
		return result;
	}
}

@@ -1490,14 +1490,48 @@
  );%0A
+%0A
 %09%09
-if (
+final Optional%3CPath%3E ignoreRuleFile =
  Rec
@@ -1564,16 +1564,39 @@
 leFile()
+;%0A%09%09if ( ignoreRuleFile
 .isPrese
@@ -1643,38 +1643,17 @@
 reImpl( 
-RecheckIgnoreUtil.getI
+i
 gnoreRul
@@ -1657,18 +1657,16 @@
 RuleFile
-()
 .get() )
@@ -1673,16 +1673,17 @@
  );%0A%09%09%7D%0A
+%0A
 %09%09return

Extract that piece of code, so sonarcloud can understand it...