Skip to content

Commit 6486b54

Browse files
authored
Merge pull request #128 from silinternational/develop
Release 2.15.3: Code quality improvements
2 parents 91b0d84 + 61866e6 commit 6486b54

File tree

14 files changed

+88
-26
lines changed

14 files changed

+88
-26
lines changed

Dockerfile

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,60 @@
11
FROM php:8.2-apache
2+
RUN useradd nonroot
23
LABEL maintainer="Mark Tompsett <[email protected]>"
34

45
ENV REFRESHED_AT 2023-07-12
56

67
# Make sure apt has current list/updates
8+
USER root
79
RUN apt-get update -y \
810
# Fix timezone stuff from hanging.
911
&& echo "America/New_York" > /etc/timezone \
10-
&& apt-get install -y tzdata \
12+
&& apt-get install -y --no-install-recommends tzdata \
1113
&& apt-get upgrade -y \
1214
# Install
13-
&& apt-get install -y \
15+
&& apt-get install -y --no-install-recommends \
1416
# things needed for GoogleMock objects
1517
sqlite3 \
1618
# some basics
1719
unzip wget zip \
1820
# Clean up to reduce docker image size
1921
&& apt-get clean \
20-
&& rm -rf /var/lib/apt/lists/*
22+
&& rm -rf /var/lib/apt/lists/* \
23+
# Make sure the directory we'll mount and reference is there
24+
&& mkdir -p /data
2125

22-
RUN mkdir -p /data
26+
USER nonroot
2327
WORKDIR /data
24-
COPY ./ /data
28+
COPY actions-services.yml /data
29+
COPY composer-install.sh /data
30+
COPY composer.json /data
31+
COPY composer.lock /data
32+
COPY docker-compose.yml /data
33+
COPY Dockerfile /data
34+
COPY LICENSE /data
35+
COPY Makefile /data
36+
COPY README.md /data
37+
COPY run-tests.sh /data
38+
COPY .travis.yml /data
39+
COPY SilMock/ /data/SilMock
2540

26-
RUN cd /data && ./composer-install.sh
27-
RUN mv /data/composer.phar /usr/bin/composer
41+
USER root
42+
# Make sure the development test files exist and have writable permissions
43+
RUN touch /data/SilMock/DataStore/Sqlite/Test1_Google_Service_Data.db && \
44+
touch /data/SilMock/DataStore/Sqlite/Test2_Google_Service_Data.db && \
45+
touch /data/SilMock/DataStore/Sqlite/Test3_Google_Service_Data.db && \
46+
touch /data/SilMock/DataStore/Sqlite/Test4_Google_Service_Data.db && \
47+
touch /data/SilMock/DataStore/Sqlite/Test5_Google_Service_Data.db && \
48+
touch /data/SilMock/tests/.phpunit.result.cache && \
49+
chown -R nonroot:root /data && \
50+
chmod 664 /data/SilMock/DataStore/Sqlite/Test1_Google_Service_Data.db && \
51+
chmod 664 /data/SilMock/DataStore/Sqlite/Test2_Google_Service_Data.db && \
52+
chmod 664 /data/SilMock/DataStore/Sqlite/Test3_Google_Service_Data.db && \
53+
chmod 664 /data/SilMock/DataStore/Sqlite/Test4_Google_Service_Data.db && \
54+
chmod 664 /data/SilMock/DataStore/Sqlite/Test5_Google_Service_Data.db && \
55+
chmod 664 /data/SilMock/tests/.phpunit.result.cache
56+
57+
WORKDIR /data
58+
RUN ./composer-install.sh && mv /data/composer.phar /usr/bin/composer
59+
USER nonroot
2860
RUN /usr/bin/composer install

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,5 @@ Examples
182182

183183
$aliases = $dir->users_aliases->listUsersAliases($users_email);
184184
$alias = $dir->users_aliases->delete($users_email, $alias);
185+
186+
### DEVELOPER'S NOTE: Releases should include updating the version in composer.json to match

SilMock/Google/Service/Directory/Resource/Groups.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Google\Service\Directory\Groups as GoogleDirectory_Groups;
88
use Google\Service\Directory\Alias as GoogleDirectory_GroupAlias;
99
use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Group;
10+
use SilMock\exceptions\GroupAlreadyExistsException;
11+
use SilMock\exceptions\GroupDoesNotExistException;
1012
use SilMock\Google\Service\DbClass;
1113
use SilMock\Google\Service\Directory\ObjectUtils;
1214
use SilMock\Google\Service\Groupssettings\Resource\Groups as MockGroupssettings_ResourceGroups;
@@ -92,7 +94,7 @@ public function insert(GoogleDirectory_Group $postBody, $optParams = [])
9294
$groupSettings->setWhoCanViewGroup('ALL_MEMBERS_CAN_VIEW');
9395
$mockGroupSettings->insert($groupSettings);
9496
} else {
95-
throw new Exception(
97+
throw new GroupAlreadyExistsException(
9698
"Cannot group.insert an existing group: " . $postBody->getEmail()
9799
);
98100
}
@@ -166,7 +168,7 @@ protected function isNewGroup(string $groupKey): bool
166168
public function update(string $groupKey, GoogleDirectory_Group $postBody, $optParams = []): GoogleDirectory_Group
167169
{
168170
if ($this->isNewGroup($postBody->getEmail())) {
169-
throw new Exception("Group '{$groupKey}' does not exist.");
171+
throw new GroupDoesNotExistException("Group '{$groupKey}' does not exist.");
170172
}
171173
$group = $this->get($groupKey);
172174

SilMock/Google/Service/Directory/UsersResource.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function update($userKey, $postBody)
293293
$newAlias->kind = "personal";
294294
$newAlias->primaryEmail = $postBody->primaryEmail;
295295

296-
$insertedAlias = $usersAliases->insertAssumingUserExists($newAlias);
296+
$usersAliases->insertAssumingUserExists($newAlias);
297297
}
298298
}
299299

@@ -451,10 +451,6 @@ private function doesUserMatch($entry, $query = '')
451451
)
452452
);
453453
}
454-
if (mb_strpos($checkValue, $value) === 0) {
455-
return true;
456-
} else {
457-
return false;
458-
}
454+
return mb_strpos($checkValue, $value) === 0;
459455
}
460456
}

SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function assertIsValidDelegateEmail($delegateEmail)
122122
*/
123123
protected function isValidEmailAddress($email)
124124
{
125-
return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
125+
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
126126
}
127127

128128
public function get($userId, $delegateEmail, $optParams = array())

SilMock/Google/Service/Gmail/Resource/UsersSettingsForwardingAddresses.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function assertIsValidDelegateEmail($delegateEmail)
4242
*/
4343
protected function isValidEmailAddress(string $email): bool
4444
{
45-
return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
45+
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
4646
}
4747

4848
/**

SilMock/Google/Service/Groupssettings/Resource/Groups.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Groups;
7+
use SilMock\exceptions\GroupSettingsDoNotExistException;
78
use SilMock\Google\Service\DbClass;
89
use SilMock\Google\Service\Directory\ObjectUtils;
910

@@ -35,7 +36,7 @@ public function delete(string $groupKey)
3536
protected function doGroupsSettingsExist(string $groupKey): bool
3637
{
3738
$groupsSettings = $this->get($groupKey);
38-
return ($groupsSettings !== null);
39+
return $groupsSettings !== null;
3940
}
4041

4142
public function get(string $groupKey): ?GoogleGroupsSettings_Groups
@@ -79,7 +80,7 @@ public function update(
7980
$optParams = []
8081
): GoogleGroupsSettings_Groups {
8182
if (! $this->doGroupsSettingsExist($postBody->getEmail())) {
82-
throw new Exception("Group Settings for '{$groupKey}' does not exist.");
83+
throw new GroupSettingsDoNotExistException("Group Settings for '{$groupKey}' does not exist.");
8384
}
8485
$groupsSettings = $this->get($groupKey);
8586

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SilMock\exceptions;
4+
5+
use Exception;
6+
7+
class GroupAlreadyExistsException extends Exception
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SilMock\exceptions;
4+
5+
use Exception;
6+
7+
class GroupDoesNotExistException extends Exception
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SilMock\exceptions;
4+
5+
use Exception;
6+
7+
class GroupSettingsDoNotExistException extends Exception
8+
{
9+
}

0 commit comments

Comments
 (0)