Skip to content
This repository was archived by the owner on May 18, 2024. It is now read-only.

Commit c9b2cf1

Browse files
committed
Apply static analysis and fixes
1 parent 426ca0c commit c9b2cf1

File tree

6 files changed

+112
-57
lines changed

6 files changed

+112
-57
lines changed

app/Controllers/BaseController.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
use App\Libraries\GitHubHelper;
66
use CodeIgniter\Controller;
7+
use CodeIgniter\HTTP\Exceptions\HTTPException;
78
use CodeIgniter\HTTP\RequestInterface;
89
use CodeIgniter\HTTP\ResponseInterface;
910
use CodeIgniter\HTTP\Response;
11+
use Config\App;
1012
use Config\Services;
1113
use Psr\Log\LoggerInterface;
1214

@@ -23,9 +25,34 @@
2325

2426
class BaseController extends Controller
2527
{
28+
/**
29+
* @var App
30+
*/
31+
protected $config;
32+
33+
/**
34+
* @var array
35+
*/
36+
protected $errors;
37+
38+
/**
39+
* Parameters for view components
40+
*
41+
* @var array
42+
*/
43+
protected $data = [];
2644

27-
protected $data = []; // parameters for view components
28-
protected $id; // identifier for our content
45+
/**
46+
* Identifier for our content
47+
*
48+
* @var mixed
49+
*/
50+
protected $id;
51+
52+
/**
53+
* @var string|null
54+
*/
55+
protected $realUrl;
2956

3057
/**
3158
* An array of helpers to be loaded automatically upon
@@ -57,13 +84,19 @@ public function __construct()
5784
* Renders this page
5885
*
5986
* @param string $view The view file to render
60-
*
61-
* @return string
6287
*/
6388
protected function render(string $view)
6489
{
6590
// URL without the locale
66-
$this->realUrl = trim('/' . $this->request->uri->getSegment(2) . '/' . $this->request->uri->getSegment(3), '/ ');
91+
try
92+
{
93+
$this->realUrl = trim('/' . $this->request->uri->getSegment(2) . '/' . $this->request->uri->getSegment(3), '/ ');
94+
}
95+
catch (HTTPException $e)
96+
{
97+
$this->realUrl = null;
98+
}
99+
67100
if (empty($this->realUrl))
68101
$this->realUrl = 'home';
69102

@@ -91,7 +124,7 @@ protected function render(string $view)
91124
/**
92125
* Builds the localized top & bottom navbars
93126
*/
94-
private function buildNavbars()
127+
private function buildNavbars(): void
95128
{
96129
// Massage the menubar
97130
$choices = $this->config->menuChoices;

app/Controllers/Home.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function index()
2828
? 'https://github.com/codeigniter4/framework/releases/'
2929
: 'https://github.com/codeigniter4/framework/archive/' . $this->data['v4name'] . '.zip',
3030
'label' => lang('Home.block1Title'),
31-
'text' => lang('Home.block1Desc') . $this->data['v4name'] ?? ''],
31+
'text' => lang('Home.block1Desc') . ($this->data['v4name'] ?? '')],
3232
['icon' => 'book',
3333
'link' => '/user_guide/index.html',
3434
'label' => lang('Home.block2Title'),

app/Libraries/GitHubHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ public function fillHeroes(array $data): array
113113
}
114114

115115
/**
116-
* build the hit parade for this group of contributors
116+
* Build the hit parade for this group of contributors.
117117
*
118-
* @param $info
118+
* @param array $info
119119
*
120120
* @return string
121121
*/
122-
protected function hitparade($info)
122+
protected function hitparade(array $info)
123123
{
124124
$heros = [];
125125
if ( ! empty($info))
@@ -142,7 +142,7 @@ protected function hitparade($info)
142142
/**
143143
* determine how many stars a contributor earns
144144
*
145-
* @param $contributions
145+
* @param int $contributions
146146
*
147147
* @return string
148148
*/

app/Libraries/GithubAPI.php

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
namespace App\Libraries;
33

4-
use Github;
4+
use Github\Client;
5+
use Github\HttpClient\CachedHttpClient;
6+
use Throwable;
57

68
class GithubAPI
79
{
@@ -19,34 +21,35 @@ class GithubAPI
1921
* Loads the Github API library with cache enabled by default.
2022
* Returns false on failures.
2123
*
22-
* @uses \Github\Client
24+
* @uses Client
2325
*
2426
* @return void
2527
*/
2628
public function __construct()
2729
{
28-
$this->client = new Github\Client(
29-
new\Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache'))
30-
);
30+
$this->client = new Client(new CachedHttpClient([
31+
'cache_dir' => '/tmp/github-api-cache',
32+
]));
3133
}
3234

3335
/**
3436
* Retrieves extended information about a repository given its username and repository name
3537
*
36-
* @param string the username
37-
* @param string the repository name
38-
* @return array repository information
38+
* @param string $username the username
39+
* @param string $repository the repository name
40+
*
41+
* @return array|null Repository information
3942
*/
40-
public function getRepoInfo($username, $repository)
43+
public function getRepoInfo($username, $repository): ?array
4144
{
4245
try
4346
{
4447
$info = $this->client->api('repo')->show($username, $repository);
4548
return ( ! empty($info)) ? $info : FALSE;
4649
}
47-
catch (Exception $e)
50+
catch (Throwable $e)
4851
{
49-
return FALSE;
52+
return null;
5053
}
5154
}
5255

@@ -56,20 +59,21 @@ public function getRepoInfo($username, $repository)
5659
*
5760
* Use this for CodeIgniter4.
5861
*
59-
* @param string the username
60-
* @param string the repository name
61-
* @return array releases information
62+
* @param string $username the username
63+
* @param string $repository the repository name
64+
*
65+
* @return array|null Releases information
6266
*/
63-
public function getRepoReleases($username, $repository)
67+
public function getRepoReleases($username, $repository): ?array
6468
{
6569
try
6670
{
6771
$info = $this->client->api('repo')->releases()->all($username, $repository);
6872
return ( ! empty($info)) ? $info : FALSE;
6973
}
70-
catch (Exception $e)
74+
catch (Throwable $e)
7175
{
72-
return FALSE;
76+
return null;
7377
}
7478
}
7579

@@ -78,20 +82,21 @@ public function getRepoReleases($username, $repository)
7882
*
7983
* Use this for CodeIgniter4.
8084
*
81-
* @param string the username
82-
* @param string the repository name
83-
* @return array releases information
85+
* @param string $username the username
86+
* @param string $repository the repository name
87+
*
88+
* @return array|null Releases information
8489
*/
85-
public function getLatestRelease($username, $repository)
90+
public function getLatestRelease($username, $repository): ?array
8691
{
8792
try
8893
{
8994
$info = $this->client->api('repo')->releases()->all($username, $repository);
9095
return ( ! empty($info)) ? $info[0] : FALSE;
9196
}
92-
catch (Exception $e)
97+
catch (Throwable $e)
9398
{
94-
return FALSE;
99+
return null;
95100
}
96101
}
97102

@@ -101,11 +106,12 @@ public function getLatestRelease($username, $repository)
101106
*
102107
* Use this for CodeIgniter3.
103108
*
104-
* @param string the username
105-
* @param string the repository name
106-
* @return array releases information
109+
* @param string $username the username
110+
* @param string $repository the repository name
111+
*
112+
* @return array|null Releases information
107113
*/
108-
public function getRepoTags($username, $repository)
114+
public function getRepoTags($username, $repository): ?array
109115
{
110116
try
111117
{
@@ -116,9 +122,9 @@ public function getRepoTags($username, $repository)
116122
$results[] = $value;
117123
return ( ! empty($results)) ? $results : FALSE;
118124
}
119-
catch (Exception $e)
125+
catch (Throwable $e)
120126
{
121-
return FALSE;
127+
return null;
122128
}
123129
}
124130

@@ -127,11 +133,12 @@ public function getRepoTags($username, $repository)
127133
*
128134
* Use this for CodeIgniter3.
129135
*
130-
* @param string the username
131-
* @param string the repository name
132-
* @return array releases information
136+
* @param string $username the username
137+
* @param string $repository the repository name
138+
*
139+
* @return array|null Releases information
133140
*/
134-
public function getLatestTag($username, $repository)
141+
public function getLatestTag($username, $repository): ?array
135142
{
136143
try
137144
{
@@ -146,29 +153,30 @@ public function getLatestTag($username, $repository)
146153
}
147154
return ( ! empty($results)) ? $results[0] : FALSE;
148155
}
149-
catch (Exception $e)
156+
catch (Throwable $e)
150157
{
151-
return FALSE;
158+
return null;
152159
}
153160
}
154161

155162
/**
156163
* Retrieves top 12contributors information for a repository given its username and repository name
157164
*
158-
* @param string the username
159-
* @param string the repository name
160-
* @return array contributor information
165+
* @param string $username the username
166+
* @param string $repository the repository name
167+
*
168+
* @return array|null Contributor information
161169
*/
162-
public function getContributors($username, $repository)
170+
public function getContributors($username, $repository): ?array
163171
{
164172
try
165173
{
166174
$info = array_slice($this->client->api('repo')->contributors($username, $repository), 0, 12);
167175
return ( ! empty($info)) ? $info : FALSE;
168176
}
169-
catch (Exception $e)
177+
catch (Throwable $e)
170178
{
171-
return FALSE;
179+
return null;
172180
}
173181
}
174182

app/Models/Mybb.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
2+
23
namespace App\Models;
34

5+
use CodeIgniter\Database\BaseConnection;
6+
use Config\App;
7+
48
/**
59
* Class Mybb
610
*
@@ -11,6 +15,15 @@
1115
*/
1216
class Mybb // extends \CodeIgniter\Model
1317
{
18+
/**
19+
* @var App
20+
*/
21+
protected $config;
22+
23+
/**
24+
* @var BaseConnection|null
25+
*/
26+
protected $db;
1427

1528
/**
1629
* Are we running in mock mode?
@@ -82,8 +95,9 @@ public function __construct()
8295
* and visible=1.
8396
*
8497
* @param int $limit Number of the posts to retrieve
85-
* @param str $order Direction to order results by. Either 'asc' or 'desc'
86-
* @return null
98+
* @param string $order Direction to order results by. Either 'asc' or 'desc'
99+
*
100+
* @return array
87101
*/
88102
public function getRecentNews($limit = 5, $order = 'desc')
89103
{
@@ -118,7 +132,8 @@ public function getRecentNews($limit = 5, $order = 'desc')
118132
*
119133
* @param int $limit
120134
* @param string $order
121-
* @return null
135+
*
136+
* @return array
122137
*/
123138
public function getRecentPosts($limit = 5, $order = 'desc')
124139
{

phpstan.neon.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ parameters:
1111
- app/Config/Routes.php
1212
- app/Views/*
1313
ignoreErrors:
14-
- '#Cannot access property [\$a-z_]+ on (array|object)#'
15-
- '#Unsafe usage of new static\(\)*#'
14+
- '#Call to an undefined static method Config\\Services::[A-Za-z]+\(\)#'
1615
universalObjectCratesClasses:
1716
- CodeIgniter\Entity
1817
- Faker\Generator

0 commit comments

Comments
 (0)