Skip to content

Commit 2d44cb4

Browse files
committed
LinkAccessibilityChecker now returns minimal error per link
1 parent 2e12074 commit 2d44cb4

File tree

1 file changed

+59
-54
lines changed

1 file changed

+59
-54
lines changed

src/LinkAccessibility/Checker.php

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,40 @@ private function _eval_links(array $link_nodes, string $page_url): array
8383
break;
8484
}
8585
}
86-
if ($link_quality_eval['is_redirect'] && !$skip_redirect) {
87-
$errors[] = (object) [
88-
'type' => 'redirect',
89-
'href' => $path,
90-
'text' => $text,
91-
'html' => $html,
92-
'recommendation' => 'Use the final redirected link.'];
93-
}
9486
if ($link_quality_eval['is_dead']) {
9587
$errors[] = (object) [
9688
'type' => 'dead',
9789
'href' => $path,
9890
'text' => $text,
9991
'html' => $html,
10092
'recommendation' => 'Find an alternative working link.'];
101-
}
102-
if ($link_quality_eval['is_same_domain']) {
103-
$errors[] = (object) [
104-
'type' => 'domain overlap',
105-
'href' => $path,
106-
'text' => $text,
107-
'html' => $html,
108-
'recommendation' => 'Use relative URL.'];
109-
}
110-
if ($link_quality_eval['timed_out']) {
111-
$errors[] = (object) [
112-
'type' => 'slow connection',
113-
'href' => $path,
114-
'text' => $text,
115-
'html' => $html,
116-
'recommendation' => 'Troubleshoot why the page takes so long to load.'];
93+
} else {
94+
if ($link_quality_eval['timed_out']) {
95+
$errors[] = (object) [
96+
'type' => 'slow connection',
97+
'href' => $path,
98+
'text' => $text,
99+
'html' => $html,
100+
'recommendation' => 'Troubleshoot why the page takes so long to load.'];
101+
} else {
102+
if ($link_quality_eval['is_same_domain']) {
103+
$errors[] = (object) [
104+
'type' => 'domain overlap',
105+
'href' => $path,
106+
'text' => $text,
107+
'html' => $html,
108+
'recommendation' => 'Use relative URL.'];
109+
} else {
110+
if ($link_quality_eval['is_redirect'] && !$skip_redirect) {
111+
$errors[] = (object) [
112+
'type' => 'redirect',
113+
'href' => $path,
114+
'text' => $text,
115+
'html' => $html,
116+
'recommendation' => 'Use the final redirected link.'];
117+
}
118+
}
119+
}
117120
}
118121

119122
// check link-text accessibility
@@ -125,41 +128,43 @@ private function _eval_links(array $link_nodes, string $page_url): array
125128
'text' => $text,
126129
'html' => $html,
127130
'recommendation' => 'Use more descriptive and specific wording.'];
128-
}
129-
if (!$link_text_eval['passed_text_not_url']) {
130-
$errors[] = (object) [
131-
'type' => 'url link text',
132-
'href' => $path,
133-
'text' => $text,
134-
'html' => $html,
135-
'recommendation' => 'Use real words that describe the link.'];
136-
}
137-
if (!$link_text_eval['passed_text_length']) {
138-
$errors[] = (object) [
139-
'type' => 'bad text length',
140-
'href' => $path,
141-
'text' => $text,
142-
'html' => $html,
143-
'recommendation' => 'Ideal link text should be between 1 to 100 characters.'];
144-
}
145-
if ($link_text_eval['url_is_pdf']) {
146-
if (!$link_text_eval['text_has_pdf']) {
147-
$errors[] = (object) [
148-
'type' => 'unclear pdf link',
149-
'href' => $path,
150-
'text' => $text,
151-
'html' => $html,
152-
'recommendation' => 'Include the word "PDF" in the link.'];
153-
}
154131
} else {
155-
if ($link_text_eval['url_is_download'] &&
156-
$link_text_eval['text_has_download']) {
132+
if (!$link_text_eval['passed_text_not_url']) {
157133
$errors[] = (object) [
158-
'type' => 'unclear download link',
134+
'type' => 'url link text',
135+
'href' => $path,
136+
'text' => $text,
137+
'html' => $html,
138+
'recommendation' => 'Use real words that describe the link.'];
139+
} else {
140+
if (!$link_text_eval['passed_text_length']) {
141+
$errors[] = (object) [
142+
'type' => 'bad text length',
159143
'href' => $path,
160144
'text' => $text,
161145
'html' => $html,
162-
'recommendation' => 'Include the word "download" in the link.'];
146+
'recommendation' => 'Ideal link text should be between 1 to 100 characters.'];
147+
}
148+
}
149+
if ($link_text_eval['url_is_pdf']) {
150+
if (!$link_text_eval['text_has_pdf']) {
151+
$errors[] = (object) [
152+
'type' => 'unclear pdf link',
153+
'href' => $path,
154+
'text' => $text,
155+
'html' => $html,
156+
'recommendation' => 'Include the word "PDF" in the link.'];
157+
}
158+
} else {
159+
if ($link_text_eval['url_is_download'] &&
160+
$link_text_eval['text_has_download']) {
161+
$errors[] = (object) [
162+
'type' => 'unclear download link',
163+
'href' => $path,
164+
'text' => $text,
165+
'html' => $html,
166+
'recommendation' => 'Include the word "download" in the link.'];
167+
}
163168
}
164169
}
165170
}

0 commit comments

Comments
 (0)