Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Forms #8

Merged
merged 14 commits into from
Apr 11, 2024
Merged

More Forms #8

merged 14 commits into from
Apr 11, 2024

Conversation

renfordt
Copy link
Owner

Instead of only having a circle for InitialsAvatar this pull request creates the possibilities for squares and also hexagons.

A new enumeration named FormTypes has been added under the namespace Renfordt\Larvatar\Enum. It currently includes three form types: Circle, Square, and Hexagon.
The main changes revolve around adding the option to generate either a circle or a square form for the avatar. This is accomplished by introducing a new FormTypes Enum and allowing the form type to be set and fetched. The generate function has been altered to adapt to these changes and to generate an SVG of the correct form based on the form type selected.
Updated the code to instantiate InitialsAvatar once in the constructor instead of multiple times in getImageHTML method of the Larvatar class. This optimizes the code by creating a single InitialsAvatar object simplifying calls to its methods and improving performance.
The InitialsAvatar class has been expanded to include a hexagonal form and a rotation property. A corresponding method getHexagon has also been implemented, which generates the coordinates of a hexagon based upon the size and rotation provided. Additionally, a new public method setRotation has been added to allow setting the rotation angle.
The comparison within the condition was adjusted to use the instance variable `$this->type` instead of the local variable `$type.` This change correctly reflects the Larvatar type and ensures that the appropriate InitialsAvatar object is created when the Larvatar type is set to `InitialsAvatar`.
A new function testGetHexagon is added to the InitialsAvatarTest class. This function tests if the getHexagon method of InitialsAvatar class is working correctly by asserting the return type, dimensions, fill color, and rotation of the resulting hexagon.
The changes in this commit eliminate the assertions checking the width and height of the SVGPolygon instance, as they are not necessary for the test. Instead, it has added an assertion to verify if the SVGPolygon's points retrieval method returns an empty array.
The changes remove a needless assertion checking for the SVG Polygon rotation in the InitialsAvatarTest. This assertion was not crucial for the test's purpose or for its passing, therefore it was removed to streamline the code.
The Hexagon tests within InitialsAvatarTest.php have been updated. An expected points array has been added to improve testing precision. Now, this test compares the generated points with a predefined set of expected points, improving the robustness of the testing for the Hexagon shape in InitialsAvatar.
Added new test methods to the InitialsAvatarTest to check for the correct setRotation and setForm behaviors. These methods aim at verifying the proper setting of rotation and form properties for an InitialsAvatar instance.
The FormTypes enum from the Larvatar package is now imported in the InitialsAvatarTest file. This change is crucial in setting up certain tests, specifically the testSetForm method that was also added in this commit.
The documentation for the avatar generation method has been updated to reflect the changes in functionality. The function now returns either a string or an SVG object. The comments have also been enhanced for clarity, specifically detailing that it generates an avatar based on provided names and encoding.
This change specifically revises the return type of the generate method in InitialsAvatar.php. The function is now guaranteed to only ever return a string, whether it's an SVG format avatar or a base64-encoded avatar image. This ensures more consistent return types for better predictability.
@renfordt renfordt marked this pull request as ready for review April 11, 2024 19:06
@renfordt renfordt merged commit 4476076 into dev Apr 11, 2024
10 checks passed
@renfordt renfordt deleted the forms branch April 11, 2024 19:07
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant