Skip to content

feat: Model added with updated return type and tests - #3

Merged
achyutkneupane merged 17 commits into
masterfrom
model-implementation
Oct 28, 2025
Merged

feat: Model added with updated return type and tests#3
achyutkneupane merged 17 commits into
masterfrom
model-implementation

Conversation

@achyutkneupane

Copy link
Copy Markdown
Member

No description provided.

@achyutkneupane
achyutkneupane merged commit 03dabf4 into master Oct 28, 2025
6 checks passed
@achyutkneupane
achyutkneupane deleted the model-implementation branch October 28, 2025 17:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the HamroCDN library to use strongly-typed model objects instead of raw arrays, improving type safety and API ergonomics.

Key Changes:

  • Introduced three new model classes (Upload, User, File) to represent API responses
  • Updated all HamroCDN client methods to return Upload objects instead of arrays
  • Refactored tests to use a custom toBeUploadObject expectation and validate model objects

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/Models/User.php New model class representing user data with name and email properties
src/Models/File.php New model class representing file data with url and size properties
src/Models/Upload.php New model class representing upload data with nanoId, user, delete_at, and original file
src/HamroCDN.php Updated methods to return Upload objects; added transformation logic in index() to map arrays to Upload instances
src/Contracts/HamroCDNContract.php Updated interface signatures to reflect Upload return types instead of arrays
tests/UploadTest.php Added custom expectation and model validation test; refactored existing tests to work with Upload objects
composer.json Added nesbot/carbon dependency (unused in current implementation)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread composer.json
Comment thread src/HamroCDN.php
/**
* @return HamroCDNObjectWithPagination
*
* @throws HamroCDNException

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type documentation is missing for the index() method. While the interface declares @return UploadWithPagination, the actual implementation returns a transformed array structure with Upload objects. Consider adding a return type annotation like @return array{data: array<Upload>, meta: array{total: int, per_page: int, page: int}} to clarify the return structure.

Suggested change
* @throws HamroCDNException
* @throws HamroCDNException
* @return array{data: array<Upload>, meta: array{total: int, per_page: int, page: int}}

Copilot uses AI. Check for mistakes.
Comment thread src/HamroCDN.php
}

/**
* @throws HamroCDNException

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type documentation. Consider adding @return Upload to match the interface documentation style and clarify what is returned.

Suggested change
* @throws HamroCDNException
* @throws HamroCDNException
* @return Upload

Copilot uses AI. Check for mistakes.
Comment thread tests/UploadTest.php
Comment on lines +17 to +21
expect($upload)
->toHaveKey('nanoId')
->toHaveKey('user')
->toHaveKey('delete_at')
->toHaveKey('original');

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom expectation toBeUploadObject uses toHaveKey() on an Upload object (lines 18-21), but Upload is a class with private properties, not an array. The toHaveKey() expectation will fail when checking for keys on an object. Consider using toHaveProperty() instead, or adjust the expectation to check the getter methods directly.

Suggested change
expect($upload)
->toHaveKey('nanoId')
->toHaveKey('user')
->toHaveKey('delete_at')
->toHaveKey('original');
expect($upload->getNanoId())->not->toBeNull();
expect($upload->getUser())->not->toBeNull();
// delete_at can be null, so just check method exists
expect(method_exists($upload, 'getDeleteAt'))->toBeTrue();
expect($upload->getOriginal())->not->toBeNull();

Copilot uses AI. Check for mistakes.
Comment thread tests/UploadTest.php
Comment on lines +23 to +25
expect($upload->getOriginal())
->toHaveKey('url')
->toHaveKey('size');

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom expectation uses toHaveKey() on the result of getOriginal() which returns a File object, not an array. This will fail. Consider using toHaveProperty() or checking the getter methods directly (e.g., expect($upload->getOriginal()->getUrl())->toBeString()).

Suggested change
expect($upload->getOriginal())
->toHaveKey('url')
->toHaveKey('size');
expect($upload->getOriginal()->getUrl())
->toBeString();
expect($upload->getOriginal()->getSize())
->toBeInt();

Copilot uses AI. Check for mistakes.
Comment thread tests/UploadTest.php
->toHaveKey('size');

expect($upload->getUser())
->toBeInstanceOf(User::class);

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expectation assumes getUser() always returns a User instance, but it can return null according to the Upload model. This will cause a test failure when user is null. Consider using a conditional check: expect($upload->getUser())->toBeInstanceOf(User::class)->or->toBeNull().

Suggested change
->toBeInstanceOf(User::class);
->toBeInstanceOf(User::class)->or->toBeNull();

Copilot uses AI. Check for mistakes.
Comment thread src/HamroCDN.php
}

/**
* @throws HamroCDNException

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type documentation. Consider adding @return Upload to match the interface documentation style and clarify what is returned.

Suggested change
* @throws HamroCDNException
* @throws HamroCDNException
* @return Upload

Copilot uses AI. Check for mistakes.
Comment thread src/HamroCDN.php
}

/**
* @throws HamroCDNException

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type documentation. Consider adding @return Upload to match the interface documentation style and clarify what is returned.

Suggested change
* @throws HamroCDNException
* @throws HamroCDNException
* @return Upload

Copilot uses AI. Check for mistakes.
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.

2 participants