Skip to content

PHP Composer.json Extractor#60

Open
v1ktor0t wants to merge 10 commits into
mainfrom
php-composer-json
Open

PHP Composer.json Extractor#60
v1ktor0t wants to merge 10 commits into
mainfrom
php-composer-json

Conversation

@v1ktor0t

@v1ktor0t v1ktor0t commented Jul 9, 2026

Copy link
Copy Markdown
Member

Extractor for PHP's Composer. I'd appreciate a set of eyes on the initial version.

Note: I'm working on a PR for the version resolution code to be merged in the deps.dev/utils/resolve package.

Comment thread extractor/filesystem/language/php/composerjson/composerjson.go Outdated
return best, found
}

func GetMinimumVersion(constraint string) (string, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would add a lot of unit tests for this, also (as per linter) add some docs/examples

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that will be covered in the PR for deps.dev/utils/resolve. this implementation is just a placeholder until that gets merged

Comment thread extractor/filesystem/language/php/composerjson/composerjson_version_resolver.go Outdated
Comment thread extractor/filesystem/language/php/composerjson/composerjson_version_resolver.go Outdated
Comment thread extractor/filesystem/language/php/composerjson/composerjson_version_resolver.go Outdated
Comment thread extractor/filesystem/language/php/composerjson/composerjson_version_resolver.go Outdated
Comment thread extractor/filesystem/language/php/composerjson/composerjson_version_resolver.go Outdated

@alessandro-Doyensec alessandro-Doyensec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hello @v1ktor0t

I added a lot of suggestions on the style, the logic seems fine.

I would guess that a lot of the code would change to interact better with the depsutil library so don't stress to much on resolving the conversations here.

@alessandro-Doyensec

Copy link
Copy Markdown
Collaborator

One last suggestion: try to avoid using alias types (ex: type version [4]int) because it is usually more difficult to change their internal structure after some time.

I usually stick with using:

type versions struct{
    value [4]int
}

@v1ktor0t

Copy link
Copy Markdown
Member Author

@alessandro-Doyensec, I implemented most of the recommended updates. I'd appreciate a second look when you get the chance.


func (v version) String() string {
parts := []string{strconv.Itoa(v.parts[0]), strconv.Itoa(v.parts[1]), strconv.Itoa(v.parts[2])}
if v.parts[3] != 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might make sense to include the length of the version inside of the version struct since there might be a difference between:

v3.1.0 and v3.1

(Not sure though)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(having the length of the version inside the struct also simplifies the parseDigits logic)

Comment on lines +79 to +85
func (v version) String() string {
parts := []string{strconv.Itoa(v.parts[0]), strconv.Itoa(v.parts[1]), strconv.Itoa(v.parts[2])}
if v.parts[3] != 0 {
parts = append(parts, strconv.Itoa(v.parts[3]))
}
return strings.Join(parts, ".")
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The String func can be rewritten using fmt.Sprint()

comparators := []comparator{{">=", fromVersion}}
// upper bound is fully specified. inclusive comparison
if toVersionN >= 3 {
comparators = append(comparators, comparator{"<=", toVersion})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Early return:

return append(comparators, comparator{"<=", toVersion})


// comparator is one primitive comparison; a constraint parses to an OR-list of AND-groups of these.
type comparator struct {
op string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you rename this operand, maybe it's my fault but it wasn't clear when i first read it

@alessandro-Doyensec

Copy link
Copy Markdown
Collaborator

Overall looks good, I just added a couple of nit/style comments on the version file. Beside that ready to be shipped 🚀

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