• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bleedingdeacons / confur / 31015112238

05 Aug 2026 02:25PM UTC coverage: 95.194% (-0.1%) from 95.299%
31015112238

push

github

web-flow
chore(tooling): make PSR-12 a gate and badge the standard (#50)

* chore(tooling): exclude WordPress and test-only sniffs from PSR-12

Groundwork for making PHPCS a gate. No formatting changes here - this commit
only narrows the ruleset, adds the .gitattributes this repo was missing, and
promotes the CI step, so the reformatting that follows is reviewable on its
own.

* style: reindent with spaces and give five methods a visibility keyword

This plugin was tab-indented throughout while the rest of the suite is not,
which accounted for 2,116 of its findings across 18 files - more than a
quarter of the whole suite's. phpcbf did that reindent plus the usual
structural tidying: opening braces onto their own line, inline
if (...) { return x; } expanded, multi-line call arguments aligned,
trailing blank lines before closing braces dropped.

Not purely whitespace, so git diff -w on this commit is not empty. The
non-whitespace part is the brace and inline-control-structure restructuring
above, plus five methods that were declared with no visibility keyword and
a snake_case name:

  AcfHelper::update_acf_field   -> public static function updateAcfField
  AcfHelper::update_acf_fields  -> public static function updateAcfFields
  AcfHelper::update_acf_field2  -> public static function updateAcfField2
  AnswerShortcode::get_field    -> public function getField
  AnswerShortcode::get_the_ID   -> public function getTheId

The AcfHelper three are called only from their own tests and one commented
line in AnswerHandler; both were updated. The AnswerShortcode two are thin
wrappers that exist so the global ACF/WP calls can be swapped out in tests -
they kept their // Calls global comments, and their two internal callers
in the same class were updated. No behaviour changes.

Two file-level docblocks in GeneralShortcodes and HtmlHelper sat between a
class_exists() guard and the class they describe, which PSR-12 reads as a
misplaced file docblock. Each moved inside its gua... (continued)

1022 of 1111 new or added lines in 21 files covered. (91.99%)

3 existing lines in 3 files now uncovered.

2258 of 2372 relevant lines covered (95.19%)

4.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.6
/src/API/AnswerAPI.php
1
<?php
2

3
namespace Confur\API;
4

5
use Confur\Config\Constants;
6
use Confur\Repositories\AnswerRepository;
7
use WP_Error;
8
use WP_REST_Response;
9

10
/**
11
 * REST API endpoints for answers
12
 */
13
class AnswerAPI
14
{
15
    private AnswerRepository $answerRepository;
16

17
    public function __construct()
6 ✔
18
    {
19
        $this->answerRepository = new AnswerRepository();
6 ✔
20
    }
21

22
    /**
23
     * Register REST API routes
24
     */
25
    public function registerRoutes(): void
2 ✔
26
    {
27
        try {
28
            register_rest_route('answer/v1', '/status/(?P<n>[a-zA-Z0-9_-]+)', [
2 ✔
29
                'methods' => 'GET',
2 ✔
30
                'callback' => [$this, 'getAnswerPostStatus'],
2 ✔
31
                'permission_callback' => '__return_true', // Public endpoint - status is non-sensitive
2 ✔
32
                'args' => [
2 ✔
33
                    'n' => [
2 ✔
34
                        'required' => true,
2 ✔
35
                        'validate_callback' => function ($param) {
2 ✔
36
                            return is_string($param) && preg_match('/^[a-zA-Z0-9_-]+$/', $param);
1 ✔
37
                        },
2 ✔
38
                        'sanitize_callback' => 'sanitize_text_field',
2 ✔
39
                    ],
2 ✔
40
                ],
2 ✔
41
            ]);
2 ✔
NEW
42
        } catch (\Exception $e) {
×
NEW
43
            error_log("AnswerAPI::registerRoutes - Failed to register routes: " . $e->getMessage());
×
NEW
44
            error_log("AnswerAPI::registerRoutes - Stack trace: " . $e->getTraceAsString());
×
45
        }
46
    }
47

48
    /**
49
     * Get answer post status
50
     *
51
     * @param \WP_REST_Request $request Request object
52
     * @return WP_REST_Response|WP_Error Response or error
53
     */
54
    public function getAnswerPostStatus($request)
4 ✔
55
    {
56

57
        error_log('[AnswerAPI::getAnswerPostStatus');
4 ✔
58

59
        try {
60
            $postName = sanitize_text_field($request['n']);
4 ✔
61

62
            if (empty($postName)) {
4 ✔
63
                error_log('[AnswerAPI::getAnswerPostStatus] Empty post name received');
1 ✔
64
                return new WP_Error('invalid_request', 'Post name is required.', ['status' => 400]);
1 ✔
65
            }
66

67
            $post = get_page_by_path($postName, OBJECT, Constants::ANSWER_CUSTOM_TYPE);
3 ✔
68
            if (!$post) {
3 ✔
69
                error_log("[AnswerAPI::getAnswerPostStatus] Post not found: $postName");
1 ✔
70
                return new WP_Error('invalid_post', 'The specified post does not exist.', ['status' => 404]);
1 ✔
71
            }
72

73
            try {
74
                $status = $this->answerRepository->getAnswerStatus($post->ID);
2 ✔
75
            } catch (\Exception $e) {
1 ✔
76
                error_log("[AnswerAPI::getAnswerPostStatus] Failed to retrieve answer status for post ID {$post->ID}: " . $e->getMessage());
1 ✔
77
                return new WP_Error(
1 ✔
78
                    'repository_error',
1 ✔
79
                    'Failed to retrieve answer status.',
1 ✔
80
                    ['status' => 500]
1 ✔
81
                );
1 ✔
82
            }
83

84
            return new WP_REST_Response($status, 200);
1 ✔
NEW
85
        } catch (\Exception $e) {
×
NEW
86
            error_log("AnswerAPI::getAnswerPostStatus - Unexpected error: " . $e->getMessage());
×
NEW
87
            error_log("AnswerAPI::getAnswerPostStatus - Stack trace: " . $e->getTraceAsString());
×
NEW
88
            return new WP_Error(
×
NEW
89
                'internal_error',
×
NEW
90
                'An unexpected error occurred while processing your request.',
×
NEW
91
                ['status' => 500]
×
NEW
92
            );
×
93
        }
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc