Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public static function categoryFor($checkName)

public static function documentationFor($checkName)
{
if (preg_match("/^Unused/i", $checkName)) {
$checkName = "Unused/" . $checkName;
}
$rule = array_pop(
explode("/", $checkName)
);

$filePath = dirname(__FILE__) . "/content/" . strtolower($checkName) . ".txt";
$filePath = dirname(__FILE__) . "/content/" . strtolower($rule) . ".txt";

if (file_exists($filePath)) {
return file_get_contents($filePath);
Expand Down
16 changes: 10 additions & 6 deletions bin/build-content
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ require 'httparty'
require 'fileutils'

CONTENT_DIR = "./content"
FILE_NAME_OVERRIDES = {
"excessiveclasscomplexity" => "weightedmethodcount",
}

categories = {
cleancode: "http://phpmd.org/rules/cleancode.txt",
Expand All @@ -15,11 +18,14 @@ categories = {
}

FileUtils.rm_rf(CONTENT_DIR)
FileUtils.mkdir_p(CONTENT_DIR)

categories.each do |category, url|
category_path = "#{CONTENT_DIR}/#{category}/"
FileUtils.mkdir_p(category_path)
def file_name(header)
file_name = header.gsub(" ", "_").downcase
FILE_NAME_OVERRIDES.fetch(file_name, file_name)
end

categories.each do |category, url|
text = HTTParty.get(url).body

matches = text.split(/=+\n.*?\n=+/, 2).pop
Expand All @@ -34,7 +40,6 @@ categories.each do |category, url|
body = body.split(/This rule.*/).shift
body += "\n```"


array << body
array << title
end
Expand All @@ -45,8 +50,7 @@ categories.each do |category, url|
sections.each_slice(2) do |(header, body)|
next if header == "Remark"

file_name = header.gsub(" ", "_").downcase
File.open("#{category_path}/#{file_name}.txt", "w") do |file|
File.open("#{CONTENT_DIR}/#{file_name(header)}.txt", "w") do |file|
file.write(body)
end
end
Expand Down