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

klinge / sl-webapp / 18972011891

31 Oct 2025 12:06PM UTC coverage: 74.73% (+11.1%) from 63.602%
18972011891

push

github

klinge
Fixed phpcs errors

1662 of 2224 relevant lines covered (74.73%)

3.82 hits per line

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

92.65
/App/Controllers/SeglingController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Controllers;
6

7
use Exception;
8
use App\Services\SeglingService;
9
use App\Services\UrlGeneratorService;
10
use App\Utils\View;
11
use App\Utils\Session;
12
use Psr\Http\Message\ServerRequestInterface;
13
use Psr\Http\Message\ResponseInterface;
14
use Laminas\Diactoros\Response\RedirectResponse;
15
use Laminas\Diactoros\Response\JsonResponse;
16
use Monolog\Logger;
17

18
class SeglingController extends BaseController
19
{
20
    public function __construct(
21
        private SeglingService $seglingService,
22
        private View $view,
23
        UrlGeneratorService $urlGenerator
24
    ) {
25
        $this->urlGenerator = $urlGenerator;
14✔
26
    }
27

28
    public function list(): ResponseInterface
29
    {
30
        $seglingar = $this->seglingService->getAllSeglingar();
1✔
31

32
        $data = [
1✔
33
            "title" => "Bokningslista",
1✔
34
            "newAction" => $this->createUrl('segling-show-create'),
1✔
35
            "items" => $seglingar
1✔
36
        ];
1✔
37
        return $this->view->render('viewSegling', $data);
1✔
38
    }
39

40
    public function edit(ServerRequestInterface $request, array $params): ResponseInterface
41
    {
42
        $id = (int) $params['id'];
2✔
43
        $formAction = $this->createUrl('segling-save', ['id' => $id]);
2✔
44

45
        try {
46
            $editData = $this->seglingService->getSeglingEditData($id);
2✔
47

48
            $data = [
1✔
49
                "title" => "Visa segling",
1✔
50
                "items" => $editData['segling'],
1✔
51
                "roles" => $editData['roles'],
1✔
52
                "allaSkeppare" => $editData['allaSkeppare'],
1✔
53
                "allaBatsman" => $editData['allaBatsman'],
1✔
54
                "allaKockar" => $editData['allaKockar'],
1✔
55
                "formUrl" => $formAction
1✔
56
            ];
1✔
57
            return $this->view->render('viewSeglingEdit', $data);
1✔
58
        } catch (Exception $e) {
1✔
59
            return $this->notFoundResponse();
1✔
60
        }
61
    }
62

63
    public function save(ServerRequestInterface $request, array $params): ResponseInterface
64
    {
65
        $id = (int) $params['id'];
2✔
66
        $postData = $this->request->getParsedBody();
2✔
67
        $result = $this->seglingService->updateSegling($id, $postData);
2✔
68

69
        if ($result->success) {
2✔
70
            Session::setFlashMessage('success', $result->message);
1✔
71
            $redirectUrl = $this->createUrl($result->redirectRoute);
1✔
72
            return new RedirectResponse($redirectUrl);
1✔
73
        } else {
74
            return $this->jsonResponse(['success' => false, 'message' => $result->message]);
1✔
75
        }
76
    }
77

78
    public function delete(ServerRequestInterface $request, array $params): ResponseInterface
79
    {
80
        $id = (int) $params['id'];
2✔
81
        $result = $this->seglingService->deleteSegling($id);
2✔
82

83
        Session::setFlashMessage($result->success ? 'success' : 'error', $result->message);
2✔
84
        $redirectUrl = $this->createUrl($result->redirectRoute);
2✔
85
        return new RedirectResponse($redirectUrl);
2✔
86
    }
87

88
    public function showCreate(): ResponseInterface
89
    {
90
        $formAction = $this->createUrl('segling-create');
1✔
91
        $data = [
1✔
92
            "title" => "Skapa ny segling",
1✔
93
            "formUrl" => $formAction
1✔
94
        ];
1✔
95
        return $this->view->render('viewSeglingNew', $data);
1✔
96
    }
97

98
    public function create(): ResponseInterface
99
    {
100
        $postData = $this->request->getParsedBody();
2✔
101
        $result = $this->seglingService->createSegling($postData);
2✔
102

103
        Session::setFlashMessage($result->success ? 'success' : 'error', $result->message);
2✔
104

105
        if ($result->success && $result->seglingId) {
2✔
106
            $redirectUrl = $this->createUrl($result->redirectRoute, ['id' => $result->seglingId]);
1✔
107
        } else {
108
            $redirectUrl = $this->createUrl($result->redirectRoute);
1✔
109
        }
110

111
        return new RedirectResponse($redirectUrl);
2✔
112
    }
113

114
    public function saveMedlem(): ResponseInterface
115
    {
116
        $postData = $this->request->getParsedBody();
2✔
117
        $result = $this->seglingService->addMemberToSegling($postData);
2✔
118

119
        return $this->jsonResponse([
2✔
120
            'success' => $result->success,
2✔
121
            'message' => $result->message
2✔
122
        ]);
2✔
123
    }
124

125
    public function deleteMedlemFromSegling(): ResponseInterface
126
    {
127
        // Handle JSON request body
128
        $contentType = $this->request->getHeaderLine('Content-Type');
2✔
129
        if (strpos($contentType, 'application/json') !== false) {
2✔
130
            $body = $this->request->getBody();
×
131
            if ($body->isSeekable()) {
×
132
                $body->rewind();
×
133
            }
134
            $json = $body->getContents();
×
135
            $data = json_decode($json, true);
×
136
        } else {
137
            $data = $this->request->getParsedBody();
2✔
138
        }
139

140
        $result = $this->seglingService->removeMemberFromSegling($data);
2✔
141

142
        return $this->jsonResponse([
2✔
143
            'status' => $result->success ? 'ok' : 'fail',
2✔
144
            'error' => $result->success ? null : $result->message
2✔
145
        ]);
2✔
146
    }
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc