Skip to content

Commit

Permalink
Merge pull request #2 from apiiro/yoel/add-php-support
Browse files Browse the repository at this point in the history
Add php support
  • Loading branch information
ravyolii committed May 11, 2022
2 parents 37e1c8d + 410e2b9 commit 32ca7d8
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Following languages are currently supported:
* Go
* Rust
* Scala
* Php

### Credits

Expand Down
23 changes: 21 additions & 2 deletions calculate/calculate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ func TestDogFood(t *testing.T) {
inRange(r, average.Keywords, 30, 40)
inRange(r, average.Indentations, 350, 400)
inRange(r, average.IndentationsNormalized, 350, 400)
inRange(r, average.IndentationsDiff, 50, 60)
inRange(r, average.IndentationsDiffNormalized, 50, 60)
inRange(r, average.IndentationsDiff, 60, 70)
inRange(r, average.IndentationsDiffNormalized, 60, 70)
inRange(r, average.IndentationsComplexity, 1, 2)
inRange(r, average.IndentationsDiffComplexity*100, 20, 30)
inRange(r, average.KeywordsComplexity*100, 20, 30)
Expand Down Expand Up @@ -2037,3 +2037,22 @@ func TestCountersForRubyFullSample(t *testing.T) {
r.Equal(float64(397), math.Round(counters.IndentationsComplexity*100))
r.Equal(float64(30), math.Round(counters.IndentationsDiffComplexity*100))
}

func TestCountersForPhpFullSample(t *testing.T) {
r := assert.New(t)

counters, err := getCountersForCode(test_resources.PhpCode, "php")
r.Nil(err)
r.NotNil(counters)

r.Equal(float64(353), counters.Lines)
r.Equal(float64(156), counters.LinesOfCode)
r.Equal(float64(105), counters.Keywords)
r.Equal(float64(900), counters.Indentations)
r.Equal(float64(225), math.Round(counters.IndentationsNormalized))
r.Equal(float64(132), math.Round(counters.IndentationsDiff))
r.Equal(float64(33), math.Round(counters.IndentationsDiffNormalized))
r.Equal(float64(67), math.Round(counters.KeywordsComplexity*100))
r.Equal(float64(144), math.Round(counters.IndentationsComplexity*100))
r.Equal(float64(21), math.Round(counters.IndentationsDiffComplexity*100))
}
61 changes: 61 additions & 0 deletions calculate/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,67 @@ var languageToKeywords = map[Language][]string{
"with",
"yield",
},
"php": {
"abstract",
"and",
"as",
"break",
"callable",
"case",
"catch",
"class",
"clone",
"const",
"continue",
"declare",
"default",
"do",
"echo",
"else",
"elseif",
"enddeclare",
"endfor",
"endforeach",
"endif",
"endswitch",
"endwhile",
"extends",
"final",
"finally",
"for",
"foreach",
"function",
"global",
"goto",
"if",
"implements",
"include",
"include_once",
"instanceof",
"insteadof",
"interface",
"match",
"namespace",
"new",
"or",
"print",
"private",
"protected",
"public",
"require",
"require_once",
"return",
"static",
"switch",
"throw",
"trait",
"try",
"use",
"var",
"while",
"xor",
"yield",
},
}

var languagesWithAtSignPrefix = map[Language]bool{
Expand Down
1 change: 1 addition & 0 deletions calculate/langauges.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var languageToExtensions = map[Language][]string{
"go": {"go"},
"rust": {"rs"},
"scala": {"scala", "sc"},
"php": {"php", "phtml", "php3", "php4", "php5", "php7", "phps", "pht", "phar"},
}

var extensionToLanguage = make(map[Language]string)
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"code-complexity/options"
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"log"
"os"

"github.com/urfave/cli/v2"
)

const VERSION = "1.0.1"
const VERSION = "1.0.2"

func main() {
cli.AppHelpTemplate =
Expand Down
Loading

0 comments on commit 32ca7d8

Please sign in to comment.