Skip to content

Commit f8759cf

Browse files
williamdesDeepSeek
andcommitted
Set the developer fields through the entity API
saveFromGithub() writes the properties on the EntityInterface, which Scrutinizer reports six times as "Accessing full_name on the interface". set() is the documented way and validates the fields. Co-authored-by: DeepSeek <noreply@deepseek.com> Signed-off-by: William Desportes <williamdes@wdes.fr>
1 parent 53c3dd9 commit f8759cf

2 files changed

Lines changed: 13 additions & 49 deletions

File tree

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -270,48 +270,6 @@ parameters:
270270
count: 1
271271
path: src/Mailer/Transport/TestTransport.php
272272

273-
-
274-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$access_token\.$#'
275-
identifier: property.notFound
276-
count: 1
277-
path: src/Model/Table/DevelopersTable.php
278-
279-
-
280-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$email\.$#'
281-
identifier: property.notFound
282-
count: 1
283-
path: src/Model/Table/DevelopersTable.php
284-
285-
-
286-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$full_name\.$#'
287-
identifier: property.notFound
288-
count: 1
289-
path: src/Model/Table/DevelopersTable.php
290-
291-
-
292-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$github_id\.$#'
293-
identifier: property.notFound
294-
count: 1
295-
path: src/Model/Table/DevelopersTable.php
296-
297-
-
298-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$gravatar_id\.$#'
299-
identifier: property.notFound
300-
count: 1
301-
path: src/Model/Table/DevelopersTable.php
302-
303-
-
304-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$has_commit_access\.$#'
305-
identifier: property.notFound
306-
count: 1
307-
path: src/Model/Table/DevelopersTable.php
308-
309-
-
310-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$id\.$#'
311-
identifier: property.notFound
312-
count: 1
313-
path: src/Model/Table/DevelopersTable.php
314-
315273
-
316274
message: '#^Method App\\Model\\Table\\DevelopersTable\:\:saveFromGithub\(\) has parameter \$githubInfo with no value type specified in iterable type array\.$#'
317275
identifier: missingType.iterableValue

‎src/Model/Table/DevelopersTable.php‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Cake\Datasource\EntityInterface;
2222
use Cake\ORM\Table;
2323

24+
use function is_int;
25+
2426
/**
2527
* A developer who has access to the system.
2628
*/
@@ -37,14 +39,18 @@ class DevelopersTable extends Table
3739
*/
3840
public function saveFromGithub(array $githubInfo, string $accessToken, EntityInterface $developer): int|null
3941
{
40-
$developer->full_name = $githubInfo['name'];
41-
$developer->gravatar_id = $githubInfo['gravatar_id'];
42-
$developer->email = $githubInfo['email'];
43-
$developer->github_id = $githubInfo['id'];
44-
$developer->access_token = $accessToken;
45-
$developer->has_commit_access = $githubInfo['has_commit_access'] ? 1 : 0;
42+
$developer->patch([
43+
'full_name' => $githubInfo['name'],
44+
'gravatar_id' => $githubInfo['gravatar_id'],
45+
'email' => $githubInfo['email'],
46+
'github_id' => $githubInfo['id'],
47+
'access_token' => $accessToken,
48+
'has_commit_access' => $githubInfo['has_commit_access'] ? 1 : 0,
49+
]);
4650
if ($this->save($developer)) {
47-
return $developer->id;
51+
$id = $developer->get('id');
52+
53+
return is_int($id) ? $id : null;
4854
}
4955

5056
return null;

0 commit comments

Comments
 (0)