Skip to content

chore: use raw strings in Regex to improve readability #23

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

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *PHPStore) discoverPHPViaPHP(dir, binName string) *Version {
s.log(` Unable to run "%s --version: %s"`, php, err)
return nil
}
r := regexp.MustCompile("PHP (\\d+\\.\\d+\\.\\d+)")
r := regexp.MustCompile(`PHP (\d+\.\d+\.\d+)`)
data := r.FindSubmatch(buf.Bytes())
if data == nil {
s.log(" %s is not a PHP binary", php)
Expand Down
16 changes: 8 additions & 8 deletions discovery_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *PHPStore) doDiscover() {

// phpenv
if homeDir != "" {
s.discoverFromDir(filepath.Join(homeDir, ".phpenv", "versions"), nil, regexp.MustCompile("^[\\d\\.]+(?:RC|BETA|snapshot)?$"), "phpenv")
s.discoverFromDir(filepath.Join(homeDir, ".phpenv", "versions"), nil, regexp.MustCompile(`^[\d\.]+(?:RC|BETA|snapshot)?$`), "phpenv")
}

// XAMPP
Expand All @@ -61,28 +61,28 @@ func (s *PHPStore) doDiscover() {
if out, err := exec.Command("brew", "--cellar").Output(); err == nil {
prefix := strings.Trim(string(out), "\n")
// pattern example: [email protected]/5.6.33_9
s.discoverFromDir(prefix, nil, regexp.MustCompile("^php@(?:[\\d\\.]+)/(?:[\\d\\._]+)$"), "homebrew")
s.discoverFromDir(prefix, nil, regexp.MustCompile(`^php@(?:[\d\.]+)/(?:[\d\._]+)$`), "homebrew")
// pattern example: php/7.2.11
s.discoverFromDir(prefix, nil, regexp.MustCompile("^php/(?:[\\d\\._]+)$"), "homebrew")
s.discoverFromDir(prefix, nil, regexp.MustCompile(`^php/(?:[\d\._]+)$`), "homebrew")
}

if runtime.GOOS == "darwin" {
// Liip PHP https://php-osx.liip.ch/ (pattern example: php5-7.2.0RC1-20170907-205032/bin/php)
s.discoverFromDir("/usr/local", nil, regexp.MustCompile("^php5\\-[\\d\\.]+(?:RC|BETA)?\\d*\\-\\d+\\-\\d+$"), "Liip PHP")
s.discoverFromDir("/usr/local", nil, regexp.MustCompile(`^php5\-[\d\.]+(?:RC|BETA)?\d*\-\d+\-\d+$`), "Liip PHP")

// MAMP
s.discoverFromDir("/Applications/MAMP/bin/php/", nil, regexp.MustCompile("^php[\\d\\.]+(?:RC|BETA)?$"), "MAMP")
s.discoverFromDir("/Applications/MAMP/bin/php/", nil, regexp.MustCompile(`^php[\d\.]+(?:RC|BETA)?$`), "MAMP")

// MacPorts (/opt/local/sbin/php-fpm71, /opt/local/bin/php71)
s.discoverFromDir("/opt/local", regexp.MustCompile("^php(?:[\\d\\.]+)$"), nil, "MacPorts")
s.discoverFromDir("/opt/local", regexp.MustCompile(`^php(?:[\d\.]+)$`), nil, "MacPorts")
}

if runtime.GOOS == "linux" {
// Ondrej PPA on Linux (bin/php7.2)
s.discoverFromDir("/usr", regexp.MustCompile("^php(?:[\\d\\.]+)$"), nil, "Ondrej PPA")
s.discoverFromDir("/usr", regexp.MustCompile(`^php(?:[\d\.]+)$`), nil, "Ondrej PPA")

// Remi's RPM repository
s.discoverFromDir("/opt/remi", nil, regexp.MustCompile("^php(?:\\d+)/root/usr$"), "Remi's RPM")
s.discoverFromDir("/opt/remi", nil, regexp.MustCompile(`^php(?:\d+)/root/usr$`), "Remi's RPM")
}

// asdf-vm
Expand Down